当前位置:Gxlcms > PHP教程 > Apache重定向问题

Apache重定向问题

时间:2021-07-01 10:21:17 帮助过:5人阅读

访问/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重定向示例

RewriteRule ^test/b/?$  http://www.test.com/ [L,R=301]

人气教程排行