【问题标题】:Redirect urls in .htaccess.htaccess 中的重定向网址
【发布时间】:2017-01-03 19:23:02
【问题描述】:

给定一个域:

http://example.com

使用 .htaccess 文件,我想将所有 URL 重定向到 http://example.com/dummypage.html,除了那些包含模式“a1”、“b1”和“c1”的 URL。例如:

http://example.com
http://example.com/d1

将被重定向。但是

http://example.com/a1
http://example.com/b1
http://example.com/c1
http://example.com/a1/anything/...
http://example.com/b1/anything/...
http://example.com/c1/anything/...

不应重定向。我尝试按照堆栈溢出中给出的其他答案来编写规则,但没有成功。应该注意,其他 RewriteCond 和 RewriteRule 语句已经在 .htaccess 文件中声明。因此,我不知道它们是否会影响重定向结果。 .htaccess 文件是这样的:https://docs.joomla.org/Preconfigured_htaccess

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    您可以在站点根目录 .htaccess 中将此重定向规则与负前瞻正则表达式一起使用:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/+(?:a1|b1|c1|dummypage\.html)(?:/.*)?\S*\sHTTP [NC]
    RewriteRule ^ /dummypage.html [L,NC,NE,R=301]
    

    【讨论】:

    • 它没有用。此外,我必须将“dummypage.html”添加到正则表达式规则中,以停止从浏览器收到“多重重定向”错误。
    • 您的 .htaccess 中还有其他规则吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 2021-06-22
    相关资源
    最近更新 更多