的.htaccess 301重定向传递沿着旧的URL到新的URL到新、重定向、htaccess、URL

2023-09-02 11:40:53 作者:用微笑释怀

我重定向一些静态HTML文件/ URL到一些新的网址是这样的:

 重定向301 / http://newsite.com
重定向301 /pageA.html http://newsite.com/subfolder/page-a/
重定向301 /pageA-B.html http://newsite.com/subfolder/page-a/page-b/
 

然而,由此产生的URL看起来是这样的:

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

而不是

网站优化中经常听老司机说的301定向是什么意思

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

为什么会我的网址重定向通沿着老路?

解决方案

原来,它是precedence只是一个数量级。看来,第一条规则:

 重定向301 / http://newsite.com
 

立即变成一个包罗万象的。相反,为了需要扭转:

 重定向301 /pageA-B.html http://newsite.com/subfolder/page-a/page-b/
重定向301 /pageA.html http://newsite.com/subfolder/page-a/
重定向301 / http://newsite.com
 

这是我收集,我原来的路看到,在根的任何路径自动匹配的根源,因为它是那么沿着旧的URL作为参数传递本质。但扭转了订单,这是一个更加明确的比赛,然后花了precedence,因为它是在网址它试图匹配的列表的顶部。

不知道如果我解释这一操作逻辑/顺序正确的,但是这是最好的,我可以在凌晨4点总结一下这个功能=)

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?

解决方案

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 =)