0

我正在尝试将所有 .php 文件更改为 .html 扩展名,并且我使用的规则干扰了我的 .htaccess 文件中的其他规则。看来我可以让一套规则发挥作用,也可以让另一套规则发挥作用。

检查代码:

Options +FollowSymLinks
RewriteEngine On

##Locations Pages
RewriteRule    ^([^/\.]+)\.html?$                           locations.php?locationslug=$1&Submit=Submit                 [L]

##Listing Pages
RewriteRule    ^([^/\.]+)\/([^/\.]+)\.html?$                listings.php?locationslug=$1&categoryslug=$2                [L]

##Vendor Pages
RewriteRule    ^([^/\.]+)\/([^/\.]+)\/([^/\.]+)\.html?$     vendors2.php?vendorslug=$3&locationslug=$1&categoryslug=$2  [L]

RewriteRule ^(.*)\.html$ $1.php [L]

如果我将该行RewriteRule ^(.*)\.html$ $1.php [L]作为文件的第 3 行,则平面 .php 页面将作为 .html 工作,但是,以下规则会引发错误(404 Not Found)。

如果我将该行RewriteRule ^(.*)\.html$ $1.php [L]作为最后一行,则平面页面将无法用作 .html。

与往常一样,非常感谢任何建设性的意见。提前致谢!

4

1 回答 1

0

Try changing the order of these rules from most specific to most generic ones like this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

##Vendor Pages
RewriteRule ^([^/]+)/([^/]+)/([^.]+)\.html?$ vendors2.php?vendorslug=$3&locationslug=$1&categoryslug=$2 [L,QSA,NC]

##Listing Pages
RewriteRule ^([^/]+)/([^.]+)\.html?$ listings.php?locationslug=$1&categoryslug=$2 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)\.html?$ $1.php [L,NC]

##Locations Pages
RewriteRule ^([^/.]+)\.html?$ locations.php?locationslug=$1&Submit=Submit [L,QSA,NC]

Just fyi that your rule # 3 and 4 will both match same URI pattern.

于 2013-05-08T16:10:12.600 回答