[英]Rewrite not working for some url in htaccess
For some URL my htaccess not working as it should. 对于某些URL,我的htaccess无法正常工作。 I just want to rewrite the extension of the file like php to html.
我只想重写文件的扩展名,如php到html。 But it's not working.
但它不起作用。 When I am typing URL like " http://www.example.com/myfile.php " and " http://www.example.com/myfile.html " both url are working.
当我输入“ http://www.example.com/myfile.php ”和“ http://www.example.com/myfile.html ”这样的网址时,两个网址都正常工作。 But i just want to rewrite myfile.php to myfile.html.
但我只想将myfile.php重写为myfile.html。
My htaccess rewrite rule is :- 我的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
Add this to your .htaccess file. 将此添加到您的.htaccess文件。
RewriteCond %{THE_REQUEST} \ /+myfile\.php(\s|\?) [NC]
RewriteRule ^ /myfile.html [R=301,L]
RewriteRule ^myfile\.html$ /myfile.php [NC,L]
The first rule takes care of redirecting to myfile.html
if the user tries to access myfile.php
directly. 如果用户尝试直接访问
myfile.php
则第一条规则会重定向到myfile.html
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.