的.htaccess 301重定向路径和所有子径 [英] .htaccess 301 redirect path and all child-paths

查看:210
本文介绍了的.htaccess 301重定向路径和所有子径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问例如www.thisdomain.com/docs/path1/path2重定向到www.thatdomain.com/path1/path2

I want accesses to e.g. www.thisdomain.com/docs/path1/path2 to redirect to www.thatdomain.com/path1/path2

(注意,文档是不是新路径的一部分)

(Note that docs is not a part of the new path)

我有以下的www.thisdomain.com:

I have the following on www.thisdomain.com:

RewriteEngine on

RewriteRule ^docs/* http://www.domain.com/ [R=301,L]    

如果我访问www.thisdomain.com/docs,它引导到www.thatdomain.com,但如果我访问某个子路径类似www.thisdomain.com/docs/path1/path2失败。是否有可能重定向拦截子路径访问和重定向,因为我需要什么?如果是这样,任何指针?

If I access www.thisdomain.com/docs, it directs to www.thatdomain.com, but if I access a child-path like www.thisdomain.com/docs/path1/path2 it fails. Is it possible for the redirect to intercept the child-path access and redirect as I need? If so, any pointers?

感谢。

推荐答案

通过定期EX pressions,*表示任何数量的的previous原子的,这将匹配/文档和/文档/。试试这个:

With regular expressions, * means any number of the previous atom, which will match /docs and /docs/. Try this:

RewriteEngine on
RewriteRule ^docs$ http://www.domain.com/ [R=301,L,QSA]
RewriteRule ^docs/(.*) http://www.domain.com/$1 [R=301,L,QSA]

QSA 是查询字符串追加,所以 /文档/富?吧=巴兹不会丢失?巴=巴兹

(QSA is query string append, so /docs/foo?bar=baz won't lose the ?bar=baz.)

这篇关于的.htaccess 301重定向路径和所有子径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆