htaccess 重定向 301 的意外行为

htaccess 重定向 301 的意外行为

我的 .htaccess 文件中有以下内容-

Redirect 301 / http://www.foo.com/south-carolina-real-estate/
Redirect 301 /related/aiken-sc.htm?tkn=MXNDbGxQjEAKEwj0qrmMz_OYAhUdBGoKHY43MKwYASAFMKCTDDgNUKCTDFDLuosP http://www.foo.com/south-carolina-real-estate/
Redirect 301 /related/aiken-sc.htm http://www.foo.com/south-carolina-real-estate/
Redirect 301 /related/spartanburg.htm?tkn=0bzl_HmfIxIKEwj0qrmMz_OYAhUdBGoKHY43MKwYASADMKCTDDgNUKCTDFDLuosP http://www.foo.com/south-carolina-real-estate/
Redirect 301 /related/spartanburg.htm http://www.foo.com/south-carolina-real-estate/

但当我访问http://www.url.com/related/aiken-sc.htm我在浏览器中看到以下 URL-

http://www.foo.com/south-carolina-real-estate/related/aiken-sc.htm

不确定问题是什么,这在其他网站上运行良好……?

答案1

尝试使用网络嗅探器跟踪正在发生的事情。Web Sniffer 不会跟踪重定向:它会显示发送的所有 HTTP 标头。

要记住的一件事是,重定向应该使用 HTTP 标头“Location:”。

答案2

重新排列您的重定向,使其从最具体到最不具体;重定向将匹配以您的匹配开头的任何路径元素,因此它永远不会超过第一个重定向指令。

Redirect 301 /some/full/path/file.html http://www.there.com/xx/yy/zz/foo.html
Redirect 301 /some/full/ http://www.there.com/xx/yy/
Redirect 301 / http://www.there.com/xx.html

相关内容