.htaccess rewrite subdomain to directory

前端 未结 8 1986
不思量自难忘°
不思量自难忘° 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 11:03

    I had the same problem, and found a detailed explanation in http://www.webmasterworld.com/apache/3163397.htm

    My solution (the subdomains contents should be in a folder called sd_subdomain:

    Options +FollowSymLinks -MultiViews
    
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} subdomain\.domain\.com
    RewriteCond $1 !^sd_
    RewriteRule (.*) /sd_subdomain/$1 [L]
    

提交回复
热议问题