繁体   English   中英

如何指定Apache重写规则以捕获除主页(root和index.html)以外的所有URL

[英]How do I specify an Apache rewrite rule to catch all URLs except home page (root and index.html)

我的目标是当用户键入以下URL时,将“ catchall”重定向触发到通用域/ URL:

http://domain.com/blah
http://domain.com/blah/blah2
http://domain.com/blah/blah2/file.pdf
http://domain.com/blah?item=1243

以上所有URL都将重定向到:

http://domain.com/about

基本上,URL可以包含斜杠和查询字符串。 而且我不希望URL为以下情况时触发重定向:

http://domain.com

要么

http://domain.com/index.html

我的解决方案是使用ErrorDocument 404或ErrorDocument 500,它们将重定向到http://domain.com/about,但是我被告知我无法执行此操作,因为正在跟踪页面404页面本身(分析等)。

目前,我有以下内容:

RewriteRule ^([A-Za-z0-9-]+)$ http://domain.com/about [NC,R=301]

这似乎有效,但不适用于上述所有情况。

任何帮助将不胜感激,我希望我已经说清楚了。

问题是您的正则表达式也匹配/about ,这导致了重定向循环。

RewriteRule ^(index\.html|)$ - [L]
RewriteRule ^(?!about) %{REQUEST_URI} [L,R=301]

或者,如果您实际只有的页面是/about/index.html ,则可以使用后备资源:

FallbackResource /about

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM