开发者

.htaccess mod_rewrite Convert file to php and don't show filetype

开发者 https://www.devze.com 2023-01-22 20:03 出处:网络
Given a set of URL as follo开发者_StackOverflow社区ws: http://site.com/filename.html http://site.com/filename.htm

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]
0

精彩评论

暂无评论...
验证码 换一张
取 消