将域a的所有请求重定向到域b的相应页面

hello all i have a domain a where my site is and now i have a short domain of my main site b i 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

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

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.