.htaccess 使用index.php而不是.html访问文件夹的HTACCESS子域

.htaccess 使用index.php而不是.html访问文件夹的HTACCESS子域,.htaccess,dns,directory,.htaccess,Dns,Directory,我已将webserver配置为使用此访问规则通过子域(blog.mydomain.com)访问子文件夹(sub_blog) RewriteBase / RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTP_HOST} blog\.mydomain\.com RewriteCond $1 !^sub_ RewriteRule (.*) /sub_blog/$1 [L] 问题是,如果我想放一个index.php页面而不是index.html,当我连

我已将webserver配置为使用此访问规则通过子域(blog.mydomain.com)访问子文件夹(sub_blog)

RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} blog\.mydomain\.com
RewriteCond $1 !^sub_
RewriteRule (.*) /sub_blog/$1 [L]
问题是,如果我想放一个index.php页面而不是index.html,当我连接到blog.mydomain.com时,我不能放一个404错误页面(找不到index.html)

我怎样才能解决这个问题?我应该添加虚拟主机吗?如果是,怎么做

/sub_blog/.htaccess文件

DirectoryIndex index.php

您只需要在.htaccess顶部添加
DirectoryIndex
指令,即可默认加载
index.php

在root.htaccess中尝试以下代码:

DirectoryIndex index.php
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$ [NC]
RewriteRule ^/?$ /sub_blog/index.php [L]

RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$ [NC]
RewriteCond $1 !^sub_blog/
RewriteRule (.+) /sub_blog/$1 [L]

为什么要重写?您可以在所需的任何目录上设置默认文档。只需添加index.php作为子目录的默认值。已尝试,不起作用。已尝试,不起作用。就像当我输入blog.mydomain.com请求blog.mydomain.com/index.html时,你是否也可以尝试使用该规则并检查我是否犯了错误?添加,相同的问题。您知道另一种本地方式(如VirtualHosts)吗?请尝试在站点root的.htaccess中更新代码(替换现有代码)。还有另一种DirectoryIndex.php。你能检查一下是我的问题还是规则问题吗?