0

I need redirect website A to website B but only main domain, keep the rest.

For example:

http://google.com/hello redirect to: http://bing.com/hello

Only change google.com to bing.com

This is code I am using but it redirect all.

<?php
header("Location: http://bing.com/hello".$_GET["tid"]);
?>

I have many keywords, so I can't redirect manually. Please help me ! Thank you ! Sorry for my poor English !

user3373322
  • 53
  • 1
  • 7
  • Do you have control over your server? Google "rewrite engine". – Floris Mar 03 '14 at 02:59
  • 1
    See http://stackoverflow.com/questions/286004/hidden-features-of-mod-rewrite - come back if you still have questions after that. – Floris Mar 03 '14 at 03:01

1 Answers1

0

Add the following lines to the .htaccess file at the root of your old domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]

This will direct everything from your olddomain.com to newdomain.com. The $1 ensures that "everything after the root" is preserved exactly as it was before. The response code 301 means "permanent redirect" - it tells the browser making the request "we have moved". The L means "this is the last statement in the processing" - so no further rules get processed for something that matched the RewriteConditions.

You have to make sure that mod_rewrite is enabled. This usually involves checking the httpd.conf file, making sure the correct line is uncommented, and restarting your server.

More info at http://www.orderofbusiness.net/blog/redirect-old-domain-to-new-domain-via-htaccess/ or https://support.google.com/webmasters/answer/93633?hl=en - or any of thousands of other sites...

Floris
  • 45,857
  • 6
  • 70
  • 122