Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

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.
0
bathazar
Asked:
bathazar
1 Solution
 
ravenplCommented:
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

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now