Given a set of URL as follo开发者_StackOverflow社区ws:
http://site.com/filename.html
http://site.com/filename.htm
http://site.com/filename.php
http://site.com/filename
Using the mod_rewrite module in .htaccess, how can I make it request the file at
http://site.com/filename.php
and show the URL
http://site.com/filename
This should satisfy your requirements:
RewriteRule ^([^\.]+)$ /$1.php [L]
EDIT: After your comment and changes in the question - try this:
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\. /$1 [R,L]
RewriteRule ^([^\.]+)$ $1.php [L]
Try these rules:
# remove file name extension and redirect externally
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]+\.(html?|php)
RewriteRule ^([^.]+)\.(html?|php)$ /$1 [L,R=301]
# rewrite to PHP file internally
RewriteRule ^[^.]+$ $0.php [L]
精彩评论