Hey, My host is absolutely terrible. For some odd reason creating a subdomain in cPanel simply does not work, and their support lines are always busy. I thought I could get around this by using .htaccess. I'm sure it's not that hard, but I'm kind of new to mod_rewrite and have had little success searching in the last 5 hours. Heres the situation:
嘿,我的主人非常可怕。由于一些奇怪的原因,在cPanel中创建子域根本不起作用,并且它们的支持行总是很忙。我以为我可以通过使用.htaccess解决这个问题。我确定它并不那么难,但我对mod_rewrite有点新意,并且在过去的5个小时内没有成功。继承人的情况:
/home/user/public_html automatically redirects to http://www.example.com
/ home / user / public_html会自动重定向到http://www.example.com
Since I'm using a CMS in public_html it has already added the rule in .htaccess to redirect anything unfamiliar after example.com/ to a 'Page Not Found'
由于我在public_html中使用CMS,因此已经在.htaccess中添加了规则,以便将example.com/之后不熟悉的任何内容重定向到“找不到页面”
/home/user/subdomain needs to redirect to http://subdomain.example.com
/ home / user / subdomain需要重定向到http://subdomain.example.com
How should I go about creating a subdomain redirection to an absolute path? Or How can I add an exception in my .htaccess
我应该如何创建一个子域重定向到绝对路径?或者如何在.htaccess中添加例外
2 个解决方案
#1
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:
我怀疑你能否让你的子域在你的public_html文件夹之外运行(虽然我不是服务器管理员)。通常,这需要DNS修改或调整服务器的配置。您是否尝试过制作子目录并重写对子域的调用?例如,这放在public_html目录中的.htaccess中:
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.
我不确定这是否可行(从不需要自己测试),但它更有可能比尝试将目标位于webhost指定的目录之外的文件定位为域文件的位置更有可能发挥作用。
Good luck!
#2
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.
但是,您的Web服务器已经需要配置,以便foobar.example.com的每个请求都被重定向到此特定虚拟主机。
#1
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:
我怀疑你能否让你的子域在你的public_html文件夹之外运行(虽然我不是服务器管理员)。通常,这需要DNS修改或调整服务器的配置。您是否尝试过制作子目录并重写对子域的调用?例如,这放在public_html目录中的.htaccess中:
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.
我不确定这是否可行(从不需要自己测试),但它更有可能比尝试将目标位于webhost指定的目录之外的文件定位为域文件的位置更有可能发挥作用。
Good luck!
#2
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.
但是,您的Web服务器已经需要配置,以便foobar.example.com的每个请求都被重定向到此特定虚拟主机。