2013-05-08 70 views
0

我正在尝试将所有.php文件更改为.html扩展名,并且我使用的规则正在干扰我的.htaccess文件中的其他规则。看来我可以得到一套规则或另一套规则。htaccess规则重命名.php为.html正在干扰其他规则

检查代码:

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未找到)。

如果我把行RewriteRule ^(.*)\.html$ $1.php [L]作为最后一行,那么这些平面页将不能用作.html。

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

回答

0

试着改变,从最具体的规则顺序最普通的人是这样的:

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] 

仅供参考,您的规则#3和4都匹配相同的URI模式。