我有一个包含一个域和一个子域的共享主机(用于移动和客户端)。每个域和子域都有不同的默认索引页面。托管公司告诉我将所有内容都放在我的 .htaccess 文件中,因为我无权访问 httpd.conf。
我想做的是这样的:
DirectoryIndex
应该是:index.html
DirectoryIndex
应该是:mobile-index.html
DirectoryIndex
应该是:post.php
DirectoryIndex
应该是:vote.php
编辑:
另外,如果我去 domain1.com/page/
DirectoryIndex
应该是:index.html
.如果我去 mobile.domain1.com/page/DirectoryIndex
应该是:mobile-index.html
我可以在我的 .htaccess 文件中放入什么来更改
DirectoryIndex
每个子域?非常感谢你
最佳答案
<IfDefine>
不会那样工作。 <IfDefine>
仅在 apache 启动时运行。您应该使用 mod_rewrite 解决方案。查看@tzakrajs 答案。
您可以在 .htaccess 文件中使用它:
SetEnvIf Host ^www\. page=www
SetEnvIf Host ^mobile\. page=mobile
rewriterule ^.*$ test.php?subdomain=%{ENV:page} [QSA,L]
只需使用
SetEnvIf
配置您的所有子域然后让 PHP 发挥它的魔力。
关于apache - 根据 .htaccess 中的域/子域更改 DirectoryIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7269685/