开发者

Htaccess Regex problem with redirect

When I use this in my htaccess file:

RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/ [R=301]

RewriteCond %{SCRIPT_FILENAME} !-f   
RewriteRule ^(.+)开发者_StackOverflow$ $1.php [NC,L] 

If you go to site.com without www it redirects to www.site.com/.php instead of www.site.com.

Any thoughts?

Thanks!


Maybe it's browser's cache from your old .htaccess? Try to empty the cache, or use other browser (or maybe Priavte Browsing).


I think at the root SCRIPT_FILENAME would be "/", which would not be considered a valid file and trip the !-f causing the rule to be applied.

Since the / is a character caught by the regex it will rewrite it to www.site.com/.php


Try to add "last" to rule by adding ",L":

RewriteRule ^(.*)$ http://www.site.com/ [R=301,L]


I ended up fixing it by adding $1 to RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]

Thanks for all your help.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜