Home  >  Article  >  Backend Development  >  Apache 重定向问题

Apache 重定向问题

WBOY
WBOYOriginal
2016-06-06 20:46:561054browse

访问/test或者/test/b重定向到http://www.test.com,要怎么写?
我写成 RedirectMatch 301 /test.* http://www.test.com时,
访问/test/b会重定向为http://www.test.com/b,但实际上需要的是http://www.test.com。

另外,要实现匹配不到某个url就重定向该怎么写?
比如当请求/admin时,不进行重定向,当请求除了/admin之外的都重定向。

回复内容:

访问/test或者/test/b重定向到http://www.test.com,要怎么写?
我写成 RedirectMatch 301 /test.* http://www.test.com时,
访问/test/b会重定向为http://www.test.com/b,但实际上需要的是http://www.test.com。

另外,要实现匹配不到某个url就重定向该怎么写?
比如当请求/admin时,不进行重定向,当请求除了/admin之外的都重定向。

请查阅有关Apache Rewrite模块的文档介绍

http://man.lupaworld.com/content/manage/Apache2.2_chinese_manual/mod/mod_rewrite.html

301重定向示例

<code class="lang-apache">RewriteRule ^test/b/?$  http://www.test.com/ [L,R=301]
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn