7

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

Like if my url is test.guru99.com/forum/xyxyxzz then it should redirect to 83answers.com. String forum can be anywhere in the url.

I have tried following

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

and also this

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

But both didn't work ,Please help me to sort this out.

Regards

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have put your code into htaccess but it's still not redirecting, i have also enabled the rewrite engine. Then i browsed to test.guru99.com/forum/5-faq/258-not-able-to-see-videos.html but it's not redirecting.
Did you restart Apache after enabling the rewrite engine?
3

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

1 Comment

How can i get parameters eg. $1 ?
2

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.