根据 .htaccess 中的域/子域更改 DirectoryIndex
我有一个共享主机,包含一个域和一个子域(用于移动设备和客户端)。每个域和子域都有不同的默认索引页。托管公司告诉我将所有内容都放在 .htaccess 文件中,因为我无权访问 httpd.conf。
我想要做的是:
- 如果用户访问domain1.com,
DirectoryIndex
应该是:index.html
- 如果用户访问mobile.domain1.com,< code>DirectoryIndex 应该是:
mobile-index.html
- 如果用户访问 post.domain1.com,
DirectoryIndex
应该是:post.php
- 如果用户访问vote.domain1.com
DirectoryIndex
应该是:vote.php
编辑: 此外,如果我访问domain1.com/page/,DirectoryIndex
应该是:index.html
。如果我转到 mobile.domain1.com/page/,DirectoryIndex
应该是:mobile-index.html
我可以在 .htaccess 文件中放入什么内容以更改每个子域的DirectoryIndex
?
非常感谢你
I have a shared hosting with one domain and one sub-domain (for mobile and clients). Each domain and sub-domains has different default index pages. The hosting company told me to put everything in my .htaccess file since I don't have access to the httpd.conf.
What I want to do is this:
- If a user goes to domain1.com the
DirectoryIndex
should be:index.html
- If a user goes to mobile.domain1.com the
DirectoryIndex
should be:mobile-index.html
- If a user goes to post.domain1.com the
DirectoryIndex
should be:post.php
- If a user goes to vote.domain1.com the
DirectoryIndex
should be:vote.php
Edit:
In addition, if I go to domain1.com/page/ the DirectoryIndex
should be: index.html
. If I go to mobile.domain1.com/page/ the DirectoryIndex
should be: mobile-index.html
What can I put in my .htaccess file in order to change the DirectoryIndex
for each sub-domain?
Thank You very mich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不会那样工作。
仅在 apache 启动时运行。您应该使用 mod_rewrite 解决方案。查看@tzakrajs 的答案。您可以在 .htaccess 文件中使用它:
只需使用
SetEnvIf
配置所有子域,然后让 PHP 发挥其魔力。<IfDefine>
does not work like that.<IfDefine>
only runs when apache starts. You should go with a mod_rewrite solution. view @tzakrajs answer.You can use this in your .htaccess file:
Simply just configure all your sub-domain using
SetEnvIf
and then simply let the PHP do its magic.试试这个:
Try this:
您可以仅使用 oyur
.htaccess
文件进行设置,如下所示:You can set using just oyur
.htaccess
file like this: