2015-02-11 76 views
0

对于某些URL,我的htaccess无法正常工作。我只是想重写文件的扩展名,如PHP到HTML。但它不起作用。当我输入URL如“http://www.example.com/myfile.php”和“http://www.example.com/myfile.html”时,两个网址都可以使用。但我只是想将myfile.php重写为myfile.html。在htaccess中重写某些url不起作用

我的htaccess重写规则是: -

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

Options -Indexes 
RewriteCond %{HTTP_HOST} ^example\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
RewriteRule ^index\.php$ "http\:\/\/example\.com\/" [R=301,L] 

Header unset Pragma 
FileETag None 
Header unset Last-Modified 
Header unset ETag 

RewriteRule ^myfile.html$ myfile.php [QSA,L] 

ServerSignature Off 

回答

0

添加到您的.htaccess文件。

RewriteCond %{THE_REQUEST} \ /+myfile\.php(\s|\?) [NC] 
RewriteRule^/myfile.html [R=301,L] 

RewriteRule ^myfile\.html$ /myfile.php [NC,L] 

的第一条规则需要重定向到myfile.html的照顾,如果用户试图直接访问myfile.php