简体   繁体   中英

redirect all requests of domain a to corrosponding page of domain b

hello all i have a domain a where my site is and now i have a short domain of my main site bi want to diect all the trafics from domain b to domain a like

www.b.com/xyz.php?id=23 to www.a.com/xyz.php?id=23

and this all by htaccess only right now i am using index page with this code

 header('location:www.domain.com'); 

if you have any idea please let me know any help is appreciated Thankyou

You need to use a rewrite condition where you check the hostname and if it equals to domain b, you redirect the user to domain a.

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

The R=301 will tell the webserver to send a HTTP 301 Moved Permanently header. The L stands for Last and will make apache stop trying to look for further matching rewrite rules.

If its going in .htaccess of your doc root, then a simple rewrite should work:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.b\.com$ [NC]
RewriteRule ^(.*)$ http://www.a.com/$1 [R,L]

This assumes you have the Rewrite module loaded in the main config file:

LoadModule rewrite_module modules/mod_rewrite.so

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM