【问题标题】:Query strings redirecting to the one the same url查询字符串重定向到一个相同的 url
【发布时间】:2018-06-12 13:54:35
【问题描述】:

我尝试使用查询字符串重定向 url 列表,但是这些 规则不起作用:
Redirect 301 /tg.php?uid=www567461d4d44a53.12485104 http://example.com/
Redirect 301 /test/?page_id=45 http://example.com/
Redirect 301 /?p=17518 http://example.com/
Redirect 301 /?page_id=5960 http://example.com/

【问题讨论】:

    标签: .htaccess redirect query-string


    【解决方案1】:

    请阅读您使用的工具的文档。 Apache 的 mod_alias 明确指出,如果您需要检查查询字符串以进行重定向而不是别名模块,则应使用重写模块。这意味着你应该使用RewriteRule's 而不是Redirect 规则:

    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} ^uid=www567461d4d44a53.12485104$
    RewriteRule ^/?tg\.php$ http://example.com/ [R=301]
    
    RewriteCond %{QUERY_STRING} ^page_id=45$
    RewriteRule ^/?test/?$ http://example.com/ [R=301]
    
    RewriteCond %{QUERY_STRING} ^p=17518$
    RewriteRule ^/?$ http://example.com/ [R=301]
    
    RewriteCond %{QUERY_STRING} ^page_id=5960$
    RewriteRule ^/?$ http://example.com/ [R=301]
    

    一般来说:您应该始终喜欢将此类规则放在 http 服务器主机配置中,而不是使用动态配置文件(“.htaccess”)。这些动态配置文件增加了复杂性,通常是意外行为的原因,难以调试,它们确实减慢了 http 服务器的速度,通常是徒劳的,它们可以打开通往安全噩梦的途径。它们仅在您无法访问真正的 http 服务器主机配置的情况下提供(阅读:非常便宜的服务提供商)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-03
      相关资源
      最近更新 更多