将子文件夹重定向到子域,并将子域请求重定向到子域index.php

时间:2018-08-20 19:20:16

标签: php apache .htaccess

我开始尝试使用.htaccess文件。在我的根目录(example.com)中,我写了一条规则,将每个第一个子文件夹重定向到一个子域。

#Starts RewriteEngine
RewriteEngine On

#Redirects every first subfolder to subdomain
RewriteCond %{HTTP_HOST} ^example
RewriteRule ^(.*)/(.*)$ http://$1.example.com/$2 [NC,QSA,L]

一切正常!

但是,如果我在子域文件夹中创建一个新的.htaccess文件,则会发生一些疯狂的事情。有时我会被重定向到index.php.example.com。有时我会收到404错误。有时是500。但是几乎每次我的基本规则都会被忽略。所以我的问题:

如何将所有请求重定向到子域的index.php,而在URL中没有index.php,而在URL中没有第一个子文件夹?

或者如何将每个请求从example.com/gamedev/my-request重定向到gamedev.example.com/index.php/my-request但使用URL gamedev.example.com/my-request

请帮助我,以便我的子域能够使用清晰美观的url处理所有请求(也适用于不存在的文件或目录)。

非常感谢!达斯·月亮

0 个答案:

没有答案