Redirect if url contains specific string using htaccess

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

As if my url is test.guru99.com/forum/xyxyxzz , it should redirect to 83answers.com . The String forum can be anywhere in the URL.

I tried to follow

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

as well as this

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

But both did not help, please help me sort it out.

Hi

+7
redirect php .htaccess
source share
3 answers

For the base URL, you do not need a RewriteCond , just a 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] 

Combined Rules:

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

Please note that you must enable http:// . If you just use 83answers.com , the server is trying to redirect the URL of your server. For example, it redirects http://test.guru99.com/forum/xyxyxzz to http://test.guru99.com/83answers.com , which is not suitable.

+8
source share

You can add an OR clause between two RewriteCond as follows:

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

The real answer that I programmed the code

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

instead of the string yoou can put your word

+1
source share

All Articles