Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 基于.htaccess中的域/子域更改目录索引_Apache_.htaccess_Mod Rewrite_Redirect_Directoryindex - Fatal编程技术网

Apache 基于.htaccess中的域/子域更改目录索引

Apache 基于.htaccess中的域/子域更改目录索引,apache,.htaccess,mod-rewrite,redirect,directoryindex,Apache,.htaccess,Mod Rewrite,Redirect,Directoryindex,我有一个与一个域和一个子域(移动和客户端)共享主机。每个域和子域都有不同的默认索引页。托管公司告诉我把所有东西都放在.htaccess文件中,因为我没有访问httpd.conf的权限 我想做的是: 如果用户访问domain1.com,DirectoryIndex应该是:index.html 如果用户访问mobile.domain1.com,DirectoryIndex应该是:mobile index.html 如果用户访问post.domain1.com,DirectoryIndex应该是:po

我有一个与一个域和一个子域(移动和客户端)共享主机。每个域和子域都有不同的默认索引页。托管公司告诉我把所有东西都放在.htaccess文件中,因为我没有访问httpd.conf的权限

我想做的是:

  • 如果用户访问domain1.com,
    DirectoryIndex
    应该是:
    index.html
  • 如果用户访问mobile.domain1.com,
    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/目录索引应该是:
    mobile index.html

    为了更改每个子域的
    DirectoryIndex
    ,我可以在.htaccess文件中放入什么

    非常感谢mich

    试试这个:

    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^domain1.com$
    RewriteRule ^.*/$ index.html [R=302,L]
    RewriteCond %{HTTP_HOST} ^mobile.domain1.com$
    RewriteRule ^.*/$ mobile-index.html [R=302,L]
    RewriteCond %{HTTP_HOST} ^post.domain1.com$
    RewriteRule ^.*/$ post.php [R=302,L]
    RewriteCond %{HTTP_HOST} ^vote.domain1.com$
    RewriteRule ^.*/$ vote.php [R=302,L]
    
    不是这样工作的<代码>仅在apache启动时运行。您应该使用mod_重写解决方案。查看@tzakrajs的答案

    您可以在.htaccess文件中使用此选项:

    SetEnvIf Host ^www\. page=www
    SetEnvIf Host ^mobile\. page=mobile
    rewriterule ^.*$ test.php?subdomain=%{ENV:page} [QSA,L]
    

    只需使用
    setenif
    配置您的所有子域,然后简单地让PHP发挥它的魔力。

    您可以只使用oyur
    .htaccess
    文件进行设置,如下所示:

    RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
    RewriteRule DirectoryIndex index.html
    
    RewriteCond %{HTTP_HOST} ^mobile.domain.com$ [NC]
    RewriteRule DirectoryIndex mobile-index.html
    
    ...
    

    谢谢,这适用于登录页,但不适用于子文件夹。例如,mobile.domain1.com/page/应该加载mobile-index.htmlright,我已经修改了规则,使它们与任何子目录(例如:domain1.com/fdskjfkls/将重定向到index.html)匹配,但没有重定向到:domain1.com/fdskjfkls/index.html和mobile.domain1.com/fdskjfkls/mobile.htmltanks进行澄清。感谢SetEnvIf,我认为这是一种更容易实现的方法(而不是创建4个不同的文件)。换句话说,感谢:
    在Apache启动后不是动态的。@laxman你不需要因为投票不适合你就否决它