Rewrite sub-domain to directory

后端 未结 2 1087
生来不讨喜
生来不讨喜 2020-12-17 05:23

I\'d like to map subdomain.example.com to www.example.com/subdomain using an internal URL rewrite that looks at the host name and simply forwards a

相关标签:
2条回答
  • 2020-12-17 05:52

    Using .htaccess:

    RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com 
    RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
    
    0 讨论(0)
  • 2020-12-17 06:01

    See the following for subdomain part if you are on Apache:

    1. You need to create a wildcard domain on your DNS server *.website.com
    2. Then in your vhost container you will need to specify the wildcard aswell *.website.com - This is done in the ServerAlias http://httpd.apache.org/docs/1.3/mod/core.html#serveralias

    Then you will want to use a rewrite rule similar to the one posted by pritaeas or get the domain with you PHP script and redirect based upon it.

    $url = substr($_SERVER['SERVER_NAME'], 0, strpos($_SERVER['SERVER_NAME'], '.'));
    header("Location: http://mydomain.com/$url");
    
    0 讨论(0)
提交回复
热议问题