Anybody available good with htaccess and mod rewrite - i want your help!

I have to rewrite the bottom a part of a url.

for instance all requestst to http://domain1.com will need to go to http://domain2.com

The demands will typically maintain the shape the following:

http://domain1.com/main/test?q=1

then i will need to go to http://domain2.com/main/test?q=2

Pleas help!

Thanks ahead of time

Spinning URL's across multiple domain names? I am unsure of this could work, thinking about Apache's request-handling formula. You are searching for a redirect, not rewrite.

Do this inside your .htaccess file:

Options +FollowSymLinks
RewriteEngine on

# redirect for http
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]  
RewriteCond %{SERVER_PORT} =80
RewriteRule ^/?(.*)$ http://domain2.com/$1 [R=301,QSA,L,NE]

# redirect for https
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]  
RewriteCond %{SERVER_PORT} =443
RewriteRule ^/?(.*)$ https://domain2.com/$1 [R=301,QSA,L,NE]

R=301 will redirect with https status 301
L can make last rule
NE is perfect for no getting away query string
QSA will append your overall query parameters

$1 is the REQUEST_URI