Map a secondary domain to a subdirectory using mod_rewrite

I am looking for a secondary domain map for a subfolder in my document root.

For example, if domain requests are www.example.commapped to my DocumentToot, then requests to www.exampletwo.comgo to /sites/files/.

I cannot redirect from www.exampletwo.com/index.htmlto www.exampletwo.com/sites/files/index.htmlwhile the url is still displayed www.exampletwo.com/index.html. Any ideas?

+3
source share
2 answers

I believe you are looking for something like this:

RewriteCond %{HTTP_HOST} ^(www\.)?exampletwo\.com [NC]
RewriteRule ^/(.*) /sites/files/$1 [L]
+5
source
RewriteCond %{HTTP_HOST}   ^(www\.)?example\.com [NC]
RewriteRule ^/(.*)         http://www.exampletwo.com/$1 [L,R]

RewriteCond %{HTTP_HOST}   ^(www\.)?exampletwo\.com [NC]
RewriteRule ^/(.*)         http://www.exampletwo.com/sites/files/$1 [L,P]

The P flag uses a proxy module, so the URL does not change (without redirecting) on ​​the client.

+1
source

Source: https://habr.com/ru/post/1788056/


All Articles