Creating SubDomains to Absolute Paths with .htaccess

☆樱花仙子☆ 提交于 2019-12-03 16:36:47

I doubt you'll be able to get your subdomain to function outside of your public_html folder (although I'm no server admin). Typically that requires DNS modifications or tweaking the server's configuration. Have you tried making a sub-directory and rewriting calls to the subdomain? For example this placed in the .htaccess within your public_html directory:

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$
RewriteRule (.*) /subdomain/$1 [L]

I'm not sure if that would work (never needed to test it myself), but it's more likely to function than trying to target files that live outside the directory specified by the webhost as the location of your domain's files.

Good luck!

Try this rule:

RewriteCond %{REQUEST_URI} !^/home/user/
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteRule ^ /home/user/%1%{REQUEST_URI} [L]

But your webserver already needs to be configured so that every request of foobar.example.com gets redirected to this specific virtual host.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!