【问题标题】:Apache redirect & rewriteApache重定向和重写
【发布时间】:2017-11-21 18:27:27
【问题描述】:

这是我的页面 http://example.com/index.html 。 我想让它像这样工作。

我已经试过了

    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^/index.html$ http://def.com

【问题讨论】:

    标签: apache redirect mod-rewrite


    【解决方案1】:

    将您的 htaccess 文件更改为:

    RewriteCond %{QUERY_STRING} ^(headers=0|)$ [NC]
    RewriteRule ^index.html$ http://def.com [R=301,L]
    

    【讨论】:

    • 嗨,现在如果我需要匹配不包含查询字符串标题的任何内容怎么办?我试过 RewriteCond %{QUERY_STRING} ^(!headers)$ [NC] RewriteRule ^index.html$ def.com [R=301,L] 但这不起作用。
    • @akimran82 RewriteCond %{QUERY_STRING} !^headers
    • 谢谢@sreedev-s-b。但我希望它和前一个一样。那么我可以将其更改为 RewriteCond %{QUERY_STRING} !^(headers=0|)$ [NC] 如果没有查询字符串或查询字符串不包含参数标题,我现在想重写/重定向跨度>
    • @akimran82 看我的第二个答案
    【解决方案2】:

    将您的 htaccess 文件更改为:

    RewriteCond %{QUERY_STRING} ^$ [OR]
    RewriteCond %{QUERY_STRING} !headers
    RewriteRule ^index.html$ http://def.com [R=301,L]
    

    【讨论】:

    • 以下命令实际上对我有用 RewriteCond %{QUERY_STRING} !headers RewriteRule ^index.html$ def.com [R=301,L]
    猜你喜欢
    • 2014-11-27
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多