3
votes

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?

1

1 Answers

1
votes

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]