【问题标题】:URL redirect via apache通过 apache 重定向 URL
【发布时间】:2018-01-10 18:37:09
【问题描述】:

我已经阅读了很多关于 apache 的教程,并且可以重定向几个 url。 虽然,有这个网址我需要做一个重定向,但我不能。任何帮助将不胜感激!谢谢 ! 注意:修改 httpd.conf

网址:https://example.com/common/webScript.jsp?path=/example/content/latest.rss?section=Insight%26type=Leadershttps://example.com

由于我已经配置了我的域,只需要重定向 网址:/common/webScript.jsp?path=/example/content/latest.rss?section=Insight%26type=Leaders到/

【问题讨论】:

    标签: apache url-redirection httpd.conf


    【解决方案1】:

    uri-path 在 "?" 之后字符是查询字符串,您需要使用 %{QUERY_STRING} ^path` 或类似的方式检查它们。粗略的例子:

    # to capture uri-path with query string starting with "path..." 
    # redirect it to /
    
    # for 2.4 with If directive (most modern)
    <If "%{QUERY_STRING} =~ m#^path#">
        RedirectMatch ^ /
    </If>
    
    
    # or with mod_rewrite that works with 2.2 too    
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^path
    RewriteRule ^ / [R,L,QSD]
    

    如果您只想将 /common/webScript.jsp 重定向到 / 做一个简单的:

    RedirectMatch ^/common/webScript.jsp /
    

    【讨论】:

    • 太棒了!谢谢 !但是我不想用查询字符串“path”来识别url,而是想识别url是否以/common/webScript.jsp开头。如果 url 以 /common/webScript.jsp 开头,想重定向到 /
    • @ShailajaKrishnamurthy 根据您的评论添加了一个新选项。
    • 嗨@ezra-s,这工作正常!谢谢!但是除了 RewriteCond 之外,还使用了 RewriteRule 而不是 RedirectMatch 并且效果很好!
    • 当你有一个你想要检查的真实条件并且只能使用 RewriteCond 完成时使用 RewriteCond,例如检查查询字符串。使用 RewriteCond 和 RewriteRule 重定向一个简单的 uri-path 是多余的。
    猜你喜欢
    • 1970-01-01
    • 2014-04-16
    • 1970-01-01
    • 1970-01-01
    • 2014-01-16
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    相关资源
    最近更新 更多