Max
Max

Reputation: 629

htaccess Redirect depending on domain.com/***/

I got the following Server structure:

SERVER

How can i redirect each domain to its depending subfolders-subfolder.

EXAMPLE:

http://domain1.de/SITE_2/
should lead to /DOMAIN_1/SITE_2/index.html
BUT only show: http://domain1.de/SITE_2/index.html

http://domain3.de/SITE_1/
should lead to /DOMAIN_3/SITE_1/index.html
BUT only show: http://domain3.de/SITE_1/index.html

At the moment i only know how to redirect depending on the added subfolders name. But this only works for ONE Domain. Each Domain has the exact same subfolders name, so this would not work. Somehow it has to be depending on the DOMAIN_NAME.

RewriteRule ^SITE_2/(.*)$ /DOMAIN_1/SITE_2 [R=301,L]
this does NOT work:
RewriteRule ^DOMAIN_2/SITE_2/(.*)$ /DOMAIN_1/SITE_2 [R=301,L]

Upvotes: 0

Views: 57

Answers (1)

Tim P
Tim P

Reputation: 26

You can use a RewriteCond for this. In your example limit the RewriteRule to a specific domain and then redirect all requests to the correct directory:

RewriteCond %{HTTP_HOST} domain1\.com$ [NC]
RewriteRule ^SITE_2/(.*)$ /DOMAIN_1/SITE_2/$1 [END]

RewriteCond %{HTTP_HOST} domain2\.com$ [NC]
RewriteRule ^SITE_1/(.*)$ /DOMAIN_2/SITE_1/$1 [END]

...

Repeat this for all domains and folders.

If there are no other files/folders on the domain that should not be redirected, you could even simplify the RewriteRule. (e.g. RewriteRule ^(.*)$ /DOMAIN_1/$1 [END])

Cheers!

Upvotes: 1

Related Questions