【问题标题】:redirect if url contains specific string using htaccess如果 url 包含使用 htaccess 的特定字符串,则重定向
【发布时间】:2014-02-26 14:13:22
【问题描述】:

如果 url 包含 forum 字符串,我想重定向到不同的域,83answers.com

如果我的网址是test.guru99.com/forum/xyxyxzz,那么它应该重定向到83answers.com。字符串论坛可以在 url 中的任何位置。

我试过了

RewriteCond %{QUERY_STRING} forum
RewriteRule .* 83answers.com [R,L]

还有这个

RewriteCond %{REQUEST_URI} forum
RewriteRule .* 83answers.com

但两者都不起作用,请帮我解决这个问题。

问候

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    我编写代码的真正答案是

    RewriteRule ^(.*)string(.*)$ http://your.website.com [R=301,L]
    

    代替字符串你可以说你的话

    【讨论】:

    • 如何获取参数,例如。 1 美元?
    【解决方案2】:

    您可以像这样在两个 RewriteCond 之间添加 OR 子句:

    RewriteCond %{QUERY_STRING} forum [OR]
    RewriteCond %{REQUEST_URI} forum
    RewriteRule ^ http://83answers.com/? [L,R=301]
    

    【讨论】:

      【解决方案3】:

      对于基本网址,您不需要RewriteCond,只需RewriteRule

      RewriteRule forum http://83answers.com [R,L]
      

      对于查询字符串,你几乎就在那里:

      RewriteCond %{QUERY_STRING} forum
      RewriteRule .? http://83answers.com [R,L]
      

      组合规则:

      RewriteRule forum http://83answers.com [R,L]
      
      RewriteCond %{QUERY_STRING} forum
      RewriteRule .? http://83answers.com [R,L]
      

      请注意,您必须包含http://。如果您只使用83answers.com,服务器会尝试重定向到您服务器上的 URL。例如,它将http://test.guru99.com/forum/xyxyxzz 重定向到http://test.guru99.com/83answers.com,这是不好的。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多