.htaccess 301 redirect passing along old url to ne

2019-08-30 09:43发布

I'm redirect some static html files/urls to some new urls like this:

Redirect 301 / http://newsite.com
Redirect 301 /pageA.html http://newsite.com/subfolder/page-a/
Redirect 301 /pageA-B.html http://newsite.com/subfolder/page-a/page-b/

however, the resulting url looks something like this:

http://newsite.com/subfolder/pageA-B.html/

instead of

http://newsite.com/subfolder/page-a/page-b/

why would my url redirect pass along the old path?

1条回答
\"骚年 ilove
2楼-- · 2019-08-30 10:15

turns out, it's just an order of precedence. It seems that first rule:

Redirect 301 / http://newsite.com

turns into a catch-all immediately. Instead, the order needs to be reversed:

Redirect 301 /pageA-B.html http://newsite.com/subfolder/page-a/page-b/
Redirect 301 /pageA.html http://newsite.com/subfolder/page-a/
Redirect 301 / http://newsite.com

From what I gather, my original way saw that any path off the root was automatically matching the root as it was then passing along the old url as an argument essentially. but by reversing the order, it was a more explicit match which then took precedence since it was at the top of the list of urls it was trying to match.

not sure if i'm explaining this logic/order of operations correctly, but that's the best i can summarize this functionality at 4am =)

查看更多
登录 后发表回答