3

I have three domains (domain1.es, domain2.com, domain3.com).

I need that:

  • domain1.es OR www.domain1.es, show the content of www.domain1.es/catalog

  • domain2.com OR www.domain2.com, redirect to www.domain1.es and show the content of www.domain1.es/catalog

  • domain3.com OR www.domain3.com, shows the content of www.domain3.com

I'm using cpanel, and I have the domain3.com like an aditional domain, configured to use the /public_html/domain3.com folder as web root folder.

I've tried with the htaccess:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /catalog/
RewriteRule ^catalog/(.*) /$1 [L,R=301]
RewriteRule !^catalog/ catalog%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} ^domain2\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
RewriteRule ^/?$ "domain1\.es" [R=301,L]

All the domains are in the same hosting, with the root folder /public_html. Then

  • www.domain1.es shows the content of /public_html/catalog
  • domain1.es shows the content of /public_html/catalog
  • www.domain2.com shows the content of /public_html/catalog
  • domain2.com shows the content of /public_html/catalog

I am writing the domain3 rules, but I am not sure.

Any idea?

Mat
  • 202,337
  • 40
  • 393
  • 406
Nerque
  • 33
  • 1
  • 3

1 Answers1

1

Use this code:

Options +FollowSymLinks -MultiViews
RewriteEngine on

# domain2.es => domain1.es/catalog
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.es$ [NC]
RewriteRule ^ http://www.domain1.es/catalog%{REQUEST_URI} [L,R=301]

# domain1.es/foo => domain1.es/catalog/foo
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.es$ [NC]
RewriteRule ^((?!catalog/).*)$ catalog/$1 [L,NC]

# domain3.es => www.domain3.es
RewriteCond %{HTTP_HOST} ^domain3\.es$ [NC]
RewriteRule ^ http://www.domain3.es/%{REQUEST_URI} [L,R=301]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • You missed domain3, and you have missing `(` in last RewriteRule – Ulrich Palha Feb 07 '12 at 15:25
  • `It doesn't work` doesn't help. Please tell me which URI didn't for you. – anubhava Feb 07 '12 at 15:27
  • [I'm having problems with this comment box, sorry] Anubhava: Thanks, but it doesn't work. I have tried: Options +FollowSymLinks -MultiViews RewriteEngine on # domain2.com => domain1.es/catalog RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC] RewriteRule ^ http://domain1.es/catalog%{REQUEST_URI} [L,R=301] # domain1.es/foo => domain1.es/catalog/foo RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.es$ [NC] RewriteRule ^(?!catalog/).*)$ catalog/$1 [L,NC] With this all the domains are in error. – Nerque Feb 07 '12 at 15:31
  • Thanks for your second comment, I'm going to try again. But, at the moment, I don't know how to add the domain3 to work properly. – Nerque Feb 07 '12 at 15:32
  • Now it is ok :-). Thanks for all. I've tried with: Options +FollowSymLinks -MultiViews RewriteEngine on # domain2.com => www.domain1.es RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC] RewriteRule ^ http://www.domain1.es%{REQUEST_URI} [L,R=301] # domain1.es/foo => domain1.es/catalog/foo RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.es$ [NC] RewriteRule ^((?!catalog/).*)$ catalog/$1 [L,NC] Now the domain3 works ok :-), without more rules. Do you know a link, to learn from cero, to write htaccess rules? I have tried to search, but all the inf. is a little complicated for me. Thanks again. – Nerque Feb 07 '12 at 15:51
  • @UlrichPalha: Thanks a lot for checking the code. Nerque, I have made the edits pls check again. – anubhava Feb 07 '12 at 15:51