.htaccess redirect domain to subdirectory without changing URL

前端 未结 2 1826
梦毁少年i
梦毁少年i 2020-12-05 03:15

I have the following setup: -> domain1.com is my main domain and also document root -> domain2.com is another domain which is registered as an alias domain (means it does ex

相关标签:
2条回答
  • 2020-12-05 03:35

    Below code works perfectly for me.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteCond %{REQUEST_URI} !^/folder_name/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /folder_name/$1
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteRule ^(/)?$ folder_name/index.html [L]
    
    0 讨论(0)
  • 2020-12-05 03:39

    You can use this rule:

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

    This will prefix every request for domain2.com with /subdir if it is not already there.

    0 讨论(0)
提交回复
热议问题