gpt4 book ai didi

.htaccess - 301 重定向 - 重定向父级而不是它的子级

转载 作者:行者123 更新时间:2023-12-05 09:22:19 25 4
gpt4 key购买 nike

我将如何着手重定向父目录而不是子目录?请参阅下面我的具体问题。感谢所有帮助!

父级 -

redirect 301 /community/whats-happening http://www.stapletondenver.com/whats-happening/  
  • 重定向父目录

child -

redirect 301 /community/whats-happening/celebrating-halloween-stapleton http://www.stapletondenver.com/whats-happening/celebrating-halloween-in-stapleton/  

我尝试了一些其他选项但没有成功。见下文:

RewriteRule  ^community/whats-happening/. /whats-happening/ [R=301,L]

RewriteRule ^community/whats-happening/(.*)$ /whats-happening/$1 [R=301,NC,L]

RewriteRule ^/?community/whats-happening/?$ http://www.stapletondenver.com/whats-happening/ [R=301]

RewriteRule ^community/whats-happening/(.*) http://stapletondenver.com/whats-happening/$1 [R=301,L]
RewriteRule ^community/whats-happening/(.*)/(.*)/? http://stapletondenver.com/whats-happening/$1/ [R=301,L]

最佳答案

发生这种情况是因为您的第一次重定向。 Redirect 指令将所有子目录和文件重定向到:

Redirect 301 /abcd http://domain.com/xyz

表示

  • /abcd/ -> http://domain.com/xyz/
  • /abcd/1234/ -> http://domain.com/xyz/1234/
  • /abcd/1234/z.html -> http://domain.com/xyz/1234/z.html

等等

如果您只想重定向父目录,请使用正则表达式和带有 $ 结束字符的 RedirectMatch:

RedirectMatch 301 ^/community/whats-happening/?$ http://www.stapletondenver.com/whats-happening/  
RedirectMatch 301 ^/community/whats-happening/celebrating-halloween-stapleton/?$ http://www.stapletondenver.com/whats-happening/celebrating-halloween-in-stapleton/

关于.htaccess - 301 重定向 - 重定向父级而不是它的子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27851475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com