redirect if url contains specific string using htaccess

后端 未结 3 1316
故里飘歌
故里飘歌 2021-01-12 10:28

I want to redirect to different domain, 83answers.com if url contains forum string.

Like if my url is test.guru99.com/forum/xyxyxzz<

相关标签:
3条回答
  • 2021-01-12 10:45

    For the base URL, you don't need RewriteCond, just RewriteRule:

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

    For the query string, you were almost there:

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

    The combined rules:

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

    Note that you must include http://. If you just use 83answers.com, the server tries to redirect to a URL on your server. For example, it would redirect http://test.guru99.com/forum/xyxyxzz to http://test.guru99.com/83answers.com, which is no good.

    0 讨论(0)
  • 2021-01-12 11:03

    Real answer that i maded code is

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

    in place of string yoou can put your word

    0 讨论(0)
  • 2021-01-12 11:06

    You can add an OR clause between two RewriteCond like this:

    RewriteCond %{QUERY_STRING} forum [OR]
    RewriteCond %{REQUEST_URI} forum
    RewriteRule ^ http://83answers.com/? [L,R=301]
    
    0 讨论(0)
提交回复
热议问题