将所有请求重定向到子文件夹

时间:2014-09-03 10:05:11

标签: php apache .htaccess

我在共享主机上有一个网站,我想将所有调用重定向到子文件夹。

E.g:

www.xxx.com/a/b/c

重定向到位于以下位置的脚本:

/docroot/public/index.php

当然我需要保留a/b/c,以便index.php脚本找出要调用的控制器等等。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你的.htaccess文件应该是这样的:

# Turn rewriting on
Options +FollowSymLinks
RewriteEngine On
# Redirect requests to index.php
RewriteCond %{REQUEST_URI} !=/docroot/public/index.php
RewriteRule .* /docroot/public/index.php

然后在index.php中,您可以阅读所有请求URL部分:

$parts = explode('/', $_SERVER['REQUEST_URI']);
// $parts is an array containing a, b, c...
相关问题