.htaccess rewrite subdomain to directory

前端 未结 8 1987
不思量自难忘°
不思量自难忘° 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条回答
  •  萌比男神i
    2020-11-22 11:01

    For any sub domain request, use this:

    RewriteEngine on 
    RewriteCond %{HTTP_HOST} !^www\.band\.s\.co 
    RewriteCond %{HTTP_HOST} ^(.*)\.band\.s\.co 
    RewriteCond %{REQUEST_URI} !^/([a-zA-Z0-9-z\-]+) 
    RewriteRule ^(.*)$ /%1/$1 [L] 
    

    Just make some folder same as sub domain name you need. Folder must be exist like this: domain.com/sub for sub.domain.com.

提交回复
热议问题