首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >301重定向-重定向父母但不是孩子

301重定向-重定向父母但不是孩子
EN

Stack Overflow用户
提问于 2015-01-08 23:33:51
回答 1查看 2.6K关注 0票数 2

如何重定向父目录,而不是子目录?见下面我的具体问题。所有的帮助和任何帮助都是感激的!

亲本-

代码语言:javascript
复制
redirect 301 /community/whats-happening http://www.stapletondenver.com/whats-happening/  
  • 重定向父目录

Child -

代码语言:javascript
复制
redirect 301 /community/whats-happening/celebrating-halloween-stapleton http://www.stapletondenver.com/whats-happening/celebrating-halloween-in-stapleton/  
  • 不正确地重定向到http://www.stapletondenver.com/whats-happening/celebrating-halloween-stapleton

,我尝试过其他几种选择,但都没有成功。见下文:

代码语言:javascript
复制
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]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-09 00:59:41

这是因为你的第一次重定向。Redirect指令将所有子目录和文件重定向到,因此:

代码语言:javascript
复制
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

等。

如果只希望父目录重定向,请使用带有$结束字符的regex和$

代码语言:javascript
复制
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/
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27851475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档