htaccess get domain name from %{HTTP_HOST} into variable, minus the www

后端 未结 1 1674
北海茫月
北海茫月 2021-01-18 13:47

I currently have the following in a htaccess file which redirects certain requests to the requested domain\'s individual folder if the file does not exist in the root..

相关标签:
1条回答
  • 2021-01-18 14:12

    You can capture the needed host part with a RewriteCond and use it as %1 in the RewriteRule

    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
    RewriteRule ^$ ASSETS/%1/index.php [L]
    

    An alternative solution at the file system level (without htaccess) might be symbolic links. Instead of extracting the necessary host part, have symbolic links to the real directory, e.g.

    - ASSETS -+-domain1.com (directory)
              |
              +-www.domain1.com -> domain1.com (symbolic link)
              |
              +-domain2.com (directory)
              |
              +-www.domain2.com -> domain2.com (symbolic link)
    
    0 讨论(0)
提交回复
热议问题