0

我正在研究飞机网站并使用 .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
4

2 回答 2

4

事实证明,Apache 的 Multiviews 功能默认情况下是打开的,这最终对我的大多数重写器都有效,但它覆盖了它们并导致了列出的 4 个失败。我所要做的就是将它添加到我的 htaccess 文件的顶部:

Options -MultiViews
于 2012-02-23T17:18:32.613 回答
0

以下是我将如何更改您的重写规则:

AddType application/x-httpd-php /(.*)
Options +FollowSymLinks
RewriteEngine On

RewriteRule ^/?$ /index.php [NC,QSA,L]
RewriteRule ^(tour|cart|links|about|military(-models)?|general-aviation|commercial|contact)/?$ /$1.php [NC,QSA,L]

RewriteRule ^general-aviation-models/([^/]+)/(.*) /models.php?mfg=$1&model=$2 [NC,QSA,L]
RewriteRule ^general-aviation-models/(.+) /models.php?mfg=$1 [NC,QSA,L]

RewriteRule ^general-aviation/([^/]+)/(.*) /general.php?page=$1&sub=$2 [NC,QSA,L]
RewriteRule ^general-aviation/(.+)  /general.php?page=$1 [NC,QSA,L]

RewriteRule ^military-models/([^/]+)/(.*) /military-models.php?mfg=$1&model=$2 [NC,QSA,L]
RewriteRule ^military-models/(.+) /military-models.php?mfg=$1 [NC,QSA,L]

RewriteRule ^commercial/([^/]+)/([^/]+) /commercial.php?page=$1&sub=$2 [NC,QSA,L]
RewriteRule ^commercial/(.+)  /commercial.php?page=$1 [NC,QSA,L]

RewriteRule ^military/([^/]+) /military.php?page=$1 [NC,QSA,L]
RewriteRule ^tour/(.+)  /tour.php?page=$1 [NC,QSA,L]

ExpiresDefault "access plus 10 years"
AddOutputFilterByType DEFLATE text/plain

顺便说一句,我很抱歉这么说,但你的设计还有改进的余地。

一般来说,人们将所有重定向到index.php然后解码URLPHP 代码。

想想看;)

于 2012-01-28T09:45:16.187 回答