301 redirect with more than one domain... in .htaccess

My hosted parked more than domain such as:

abc.com
bcd.com
efg.travel

I have this to do 301 redirect:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.efg\.travel [NC]
RewriteRule ^(.*)$ http://www.efg.travel/$1 [L,R=301]

But i want use this redirect for another domain which is parked to the same host.
I used this code:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.efg\.travel [NC]
RewriteRule ^(.*)$ http://www.efg.travel/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.abc\.com [NC]
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R=301]

But it does not work. Can you solve my problem for me ? Thank u very much.
bathazarAsked:
Who is Participating?
 
ravenplConnect With a Mentor Commented:
I Your new exapmple, first rule almost always match (it does not only for HTTP_HOST set to www.efg.travel).
RewriteCond %{HTTP_HOST} !^www\.efg\.travel [NC] # means if user entered in his browser something other than www.efg.travel
No wonder, the second rule never (almost) fires.

You need to rethink Your conditions for redirecting.
eg: redirect to www.... if no www. was typed

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^efg\.travel [NC] # note stripped !
RewriteRule ^(.*)$ http://www.efg.travel/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^abc\.com [NC]
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R=301]
0
 
bathazarAuthor Commented:
Yeah ! Thank u so much !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.