Redirect wildcard subdomains to subdirectory, without changing URL in address bar

前端 未结 3 1184
别跟我提以往
别跟我提以往 2021-01-01 06:04

I\'ve read a lot of questions and answers about this on here but none that seem to solve my specific problem.

I want to redirect any subdomain to the subdirectory to

3条回答
  •  青春惊慌失措
    2021-01-01 06:28

    This can be achieved in .htaccess without mod_proxy provided your server is configured to allow wildcard subdomains. (I achieved that in JustHost by creating a subomain manually named *). Add this to your .htaccess file:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.website\.com$
    RewriteCond %{HTTP_HOST} ^(\w+)\.website\.com$
    RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
    RewriteRule ^(.*)$ /%1/$1 [QSA]
    

提交回复
热议问题