使用 .htaccess 创建绝对路径的子域
嘿,我的主人真是太糟糕了。 由于某些奇怪的原因,在 cPanel 中创建子域根本不起作用,而且他们的支持热线总是很忙。 我想我可以通过使用 .htaccess 来解决这个问题。 我确信这并不难,但我对 mod_rewrite 有点陌生,并且在过去 5 小时内搜索几乎没有成功。 情况如下:
/home/user/public_html 自动重定向到 http://www.example.com
自从我正在使用 public_html 中的 CMS,它已经在 .htaccess 中添加了规则,以将 example.com/ 之后不熟悉的任何内容重定向到“找不到页面”
/home/user/subdomain 需要重定向到 http://subdomain.example.com
我应该如何创建到绝对路径的子域重定向? 或者如何在 .htaccess 中添加例外
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:
/home/user/public_html automatically redirects to 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'
/home/user/subdomain needs to redirect to 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您能否让您的子域在 public_html 文件夹之外运行(尽管我不是服务器管理员)。 通常这需要修改 DNS 或调整服务器的配置。 您是否尝试过创建子目录并重写对子域的调用? 例如,将其放置在 public_html 目录中的 .htaccess 中:
我不确定这是否有效(不需要自己测试),但它比尝试定位位于指定目录之外的文件更有可能起作用。 webhost 作为域文件的位置。
祝你好运!
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:
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!
尝试这个规则:
但是您的网络服务器已经需要配置,以便
foobar
.example.com
的每个请求都被重定向到这个特定的虚拟主机。Try this rule:
But your webserver already needs to be configured so that every request of
foobar
.example.com
gets redirected to this specific virtual host.