4

自从我弄乱 .htaccess 以来已经有一段时间了,我似乎无法完全正确地做到这一点。我有一个站点,例如 example.com,我希望 example.com/* 重定向到 example.com/collector.html ,但子目录 example.com/special 下的 URL除外,我想继续工作。

例如:

  • example.com/page.html 应该重定向到 example.com/collector.html
  • example.com/foo/bar 应该重定向到 example.com/collector.html
  • example.com/special/page.html 不应重定向

我本来以为像

RedirectMatch 302 ^/[^(special)]/.* /collector.html
RedirectMatch 302 ^/[^(collector.html)/]* /collector.html

会做的伎俩,但它似乎并没有按照我想要的方式工作。

4

4 回答 4

4

也许这个?(需要 mod_rewrite)

RewriteEngine On
RewriteRule !^(special(/.*)?|collector\.html)$ collector.html [R,L]
于 2009-05-29T13:57:32.063 回答
2

这对我来说在 Apache 2.2.13 上工作得很好,我重新创建了你描述的目录结构。

RedirectMatch 302 /(?!special)  http://www.example.com/collector.html

括号中的模式表示如果 URI 包含字符串“特殊”,则不匹配。

此外,mod rewrite 并不总是可用,在这种情况下不需要。

于 2010-01-05T15:49:18.163 回答
0

试试这个:

RedirectMatch 302 /\/[^(special)]\/.+/ /collector.html 
RedirectMatch 302 /\/[^(collector\.html)]/ /collector.html
于 2009-05-29T13:29:30.810 回答
0

也许...?

RewriteEngine on
RewriteRule ^(?!special) collector.html [R,NC]
于 2009-05-29T17:56:29.147 回答