Kunwar Siddharth Singh Kunwar Siddharth Singh - 1 year ago 93
Apache Configuration Question

domain redirection in htaccess file

I want to redirect my domain landing page to other domain but I don't want to Redirect Everything After the Domain landing page.Can any one help me How I can do this. my htaccess file :-

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTP_HOST} ^women\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.women\.com$
RewriteRule ^/?$ "http\:\/\/beta\.women\.com\/" [R=301,L]

I want women.com landing page redirect to beta.women.com but women.com?post_type=in_product&p=509&preview=1 or women.com/about or everything after women.com/ not to redirect to beta.women.com

any help will be highly appreciated !

Thank you !

Answer Source

Keep redirect rule before other rules and exclude any query string from redirect using a RewriteCond:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} ^(?:www\.)?(women\.com)$ [NC]
RewriteRule ^/?$ http://beta.%1/ [R=301,L]

RewriteRule ^index\.php$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download