问题
I am trying find out how to redirect all traffic on a website from any .htm address to a .php version of the page. I am hoping it will be a .htaccess rule but I have not been able to find anything that quite fits for me yet and I am not the greatest with .htaccess.
Any help greatly appreciated.
回答1:
This will do the job in your .htaccess file:
RedirectMatch 301 (.*)\.htm$ $1.php
回答2:
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1.php [NC,L,R]
This will redirect file.html to file.php without causing an infinite looping error.
来源:https://stackoverflow.com/questions/4610973/redirect-htm-to-php