我正在研究飞机网站并使用 .htaccess 文件重写 URL,因此它们对 seo 友好。这是文件:
AddType application/x-httpd-php /(.*)
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^general-aviation-models/(.*)/(.*) /models.php?mfg=$1&model=$2
RewriteRule ^general-aviation/(.*)/(.*) /general.php?page=$1&sub=$2
RewriteRule ^general-aviation/(.*) /general.php?page=$1
RewriteRule ^general-aviation /index.php
RewriteRule ^military/(.*) /military.php?page=$1
RewriteRule ^military-models/(.*)/(.*) /military-models.php?mfg=$1&model=$2
RewriteRule ^military-models/(.*) /military-models.php?mfg=$1
RewriteRule ^cart/ /cart.php
RewriteRule ^contact/ /contact.php
RewriteRule ^commercial/(.*)/(.*) /commercial.php?page=$1&sub=$2
RewriteRule ^commercial/(.*) /commercial.php?page=$1
RewriteRule ^commercial/ /commercial.php
RewriteRule ^links/ /links.php
RewriteRule ^about/ /about.php
RewriteRule ^tour/(.*) /tour.php?page=$1
RewriteRule ^tour/ /tour.php
ExpiresDefault "access plus 10 years"
AddOutputFilterByType DEFLATE text/plain
这在我的本地开发环境中的基于 *nix 的服务器和 MAMP 上都有效,但是在迁移到 Mac OSX 服务器时,一些(但不是全部)规则失败。特别是,这些失败:
RewriteRule ^military-models/(.*)/(.*) /military-models.php?mfg=$1&model=$2
RewriteRule ^military-models/(.*) /military-models.php?mfg=$1
RewriteRule ^commercial/(.*)/(.*) /commercial.php?page=$1&sub=$2
RewriteRule ^commercial/(.*) /commercial.php?page=$1
其他注意事项:
- mod_rewrite模块成功加载(显示在 phpinfo() 的加载模块部分)
- 我的httpd.conf文件中有AllowOverride All(在适当的标签中)
- 我的服务器 API 是Apache 2.0 处理程序
我已经环顾了一段时间,但没有找到太多。我在这个 SO question中尝试了第一个解决方案,但是添加的行在我的日志中导致了这个错误:
/my_specific/document_root/.htaccess: DocumentRoot not allowed here
有什么建议么?
更新:
事实证明 Apache 的 Multiviews 功能已打开,无论如何它最终都适用于我的大多数重写器,但它覆盖了它们并导致了列出的 4 个失败。我所要做的就是将它添加到我的 htaccess 文件的顶部:
Options -MultiViews