我必须将某些文件夹从我的域重定向到子域。这些是我的.htaccess规则:
RedirectMatch 301 /folder1 http://sub.domain.com/folder1$1
RedirectMatch 301 /folder2 http://sub.domain.com/folder2$1
一切正常,这会重定向
中的所有内容www.domain.com/folder1/... => to => sub.domain.com/folder1/...
但没有挑战的世界是什么?我发现了这个问题:这条规则也重定向
www.domain.com/sub1/sub2/folder1/... => to => sub.domain.com/folder1/...
在我看来这并不好。有什么办法可以避免这种情况吗?
提前完成。
答案 0 :(得分:0)
您需要使用 ^ 和 $ 来分隔您的正则表达式模式,以便仅匹配 / folder1 。
RedirectMatch 301 ^/folder1$ http://sub.domain.com/folder1$1