【问题标题】:HTACCESS Subdomain to folder with index.php instead of .htmlHTACCESS 子域到带有 index.php 而不是 .html 的文件夹
【发布时间】:2016-03-20 11:24:34
【问题描述】:

我已将网络服务器配置为使用此 htaccess 规则通过子域 (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

【问题讨论】:

  • 为什么要重写?您可以在所需的任何目录上设置默认文档。只需添加 index.php 作为子目录的默认值。
  • 已经试过了,不行。

标签: .htaccess dns directory


【解决方案1】:

您只需要在 .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]

【讨论】:

  • 已经试过了,不行。就像我输入 blog.mydomain.com 时请求 blog.mydomain.com/index.html 你也可以尝试使用该规则并检查我是否犯了错误?
  • 已添加,同样的问题。您知道其他方法(如 VirtualHosts)吗?
  • 尝试在站点根目录的 .htaccess 中更新代码(替换您现有的代码)
  • 还有一个 DirectoryIndex index.php。你能检查一下是我的问题还是规则问题?
猜你喜欢
  • 2019-07-10
  • 2012-08-02
  • 2012-01-13
  • 1970-01-01
  • 2011-02-20
  • 1970-01-01
  • 1970-01-01
  • 2021-08-14
  • 1970-01-01
相关资源
最近更新 更多