right order of rewrite rules in an htaccess file

╄→尐↘猪︶ㄣ 提交于 2019-12-07 07:23:41

"Rule 3" isn't a rule at all, and its order relative to your RewriteRules doesn't matter. Rule 2 is failing for some other reason. I'm not sure whether it will address your problem, but I would simplify your rules somewhat by writing them like this:

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

RewriteRule ^v1/(.*) /$1 [R=301,L,NC]

RewriteCond %{REQUEST_URI} !^/v2/ [NC]
RewriteRule (.*) /v2/$1 [NC,L]

You should first write any rule that is causing an external redirect (R flag) and then the other rules. Otherwise an already rewritten URL can be used for an external redirect though it was just intended for an internal redirect.

So I won’t change the order you have right now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!