【发布时间】:2015-10-21 11:27:15
【问题描述】:
我正在尝试使用.htaccess 将子域请求重写到我的服务器中的子文件夹。我希望mail.domain.com 查看位于根目录中的mail 文件夹。我可以用下面的代码来实现这一点
RewriteEngine on
RewriteCond %{HTTP_HOST} mail.domain.com$
RewriteCond %{REQUEST_URI} !^/mail
RewriteRule ^(.*)$ /mail/$1 [L]
这工作正常。当我浏览到mail.domain.com 时,我正在获取domain.com/mail/index.php 的内容。
但是,这不适用于子域中的子文件夹。即当我浏览到mail.domain.com/installer 时,它不会提供domain.com/mail/installer/index.php 的内容。相反,它显示 404 错误。我还尝试了来自 htaccess subdomain pointing 的代码。不知何故,我无法获得输出。该方法也给出了同样的问题。我做错了什么?
注意:
- 我不想要重定向条件。想通过重写规则来实现。
- 我正在使用 openshift 服务器。创建了
domain.com和mail.domain.com别名。 - 根文件夹包含
no低于 .htaccess 规则的 wordpress。
编辑
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
当我删除上面的 wordpress htaccess 时,一切正常。所以它在子域子文件夹中导致 404 错误。请帮助我可以为 wordpress 漂亮的 url 和子域子文件夹做些什么?
注意:我真的很抱歉。 Wordpress 通过网络界面添加了这个,我没有注意到。
【问题讨论】:
-
尝试添加这条规则
RewriteCond %{REQUEST_FILENAME} !-d -
@Kamran 我试过了。现在
mail.domain.com显示来自domain.com的内容 -
@anubhava 是的。我试过了。
mail.domain.com/installer/给出 404 错误:( -
你可以在httpd的配置中set up the Virtual Host而不是使用
.htaccess吗? -
@ʰᵈˑ 我无权编辑服务器中的虚拟主机文件。所以我正在尝试使用 htaccess 方法
标签: php regex apache .htaccess mod-rewrite