.htaccess rewrite subdomain to directory

前端 未结 8 1877
不思量自难忘°
不思量自难忘° 2020-11-22 10:26

Is it possible to use .htaccess to rewrite a sub domain to a directory?

Example:

  • http://sub.domain.com/

shows the content of

8条回答
  •  逝去的感伤
    2020-11-22 10:58

    Try putting this in your .htaccess file:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^sub.domain.com
    RewriteRule ^(.*)$ /subdomains/sub/$1 [L,NC,QSA]
    

    For a more general rule (that works with any subdomain, not just sub) replace the last two lines with this:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
    RewriteRule ^(.*)$ subdomains/%1/$1 [L,NC,QSA]
    

提交回复
热议问题