Link to home
Start Free TrialLog in
Avatar of druplash
druplashFlag for Austria

asked on

Ho to redirect a domain with htaccess?

Hello,

i have 2 Domains.

www.domain1.com
www.domain2.com

1.) Every Domain haves the same webspace. If somebody type in www.domain2.com he should be redirected to www.domain1.com

2.) If somebody type in domain1.com or domain2.com (without the www.), he also should be redirected to www.domain1.com

Please can somebody explain how to solve this with htaccess on a Linux Server?

Thank´s!
Avatar of Keith Brown
Keith Brown
Flag of United States of America image

for the .htaccess in domain1
#Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Open in new window


for the .htaccess on domain2
#Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain2.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain2.com$
RewriteRule ^(.*)$ http://www.domain1.com/ [R=301,L] 

Open in new window

Avatar of druplash

ASKER

Thank´s for your reply.
But i have only 1 webspace and 1 htaccess file. Should i write all these rules in 1 htaccess file?
ASKER CERTIFIED SOLUTION
Avatar of Keith Brown
Keith Brown
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, both are sharing the same directory. And your solution works great!
Many thank´s!!!