HTACCESS redirect to folder based on hostname

Stan Hurks

I have multiple websites under the same web server.

My root structure is as following:

./

./site1/

./site2/

./.htaccess

I would like htaccess file to redirect to the correct folder.

If the user navigates to www.site1.com or site1.com it should rewrite the url to go to the ./site1/ folder and if the user navigates to www.site2.com or site2.com it should rewrite the url to go to the ./site2/ folder.

Is there any way to achieve this behaviour?

Thanks in advance.

Arjun Singh

Use following code in .htaccess file.

RewriteCond %{HTTP_HOST} ^(www\.)?site1\.com$ [NC]
RewriteRule !^site1/ /site1%{REQUEST_URI} [L,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteRule !^site2/ /site2%{REQUEST_URI} [L,NC]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related