RedirectMatch排除某些目录

时间:2015-12-23 19:25:26

标签: regex apache .htaccess redirect

我使用RedirectMatch 301将mydomain.com/example等请求重定向到示例页面。为此,我在.htaccess文件中使用以下代码:

RedirectMatch 301 (?i)/whatever http://thedomain.com

(?i)是重定向不区分大小写的。我现在想要实现的是,只有在mydomain.com之后直接放置任何东西时才有效,所以mydomain.com/sub/sub/whatever不会重定向用户。

提前致谢

1 个答案:

答案 0 :(得分:1)

使用正则表达式锚点限制匹配:

RedirectMatch 301 ^(?i)/whatever/?$ http://thedomain.com
相关问题