【发布时间】:2015-04-07 18:58:13
【问题描述】:
我的网站托管在一个子文件夹中:site.com/foo/
在foo/ 文件夹的根目录中,我有以下.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*) webroot/$1 [L]
</IfModule>
它的作用是将所有页面请求重定向到位于foo/ 文件夹中的webroot/ 子文件夹。
在那个 webroot/ 子文件夹中,我有以下 .htaccess :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php/$1 [L]
目标是所有都应该重定向到index.php。需要明确的是,文件结构是:
www/
foo/
.htaccess
webroot/
.htaccess
index.php
当我尝试访问site.com/foo/ 时,我按预期得到index.php,但是当我尝试诸如site.com/foo/bar/bar/bar 之类的随机事物时,我得到“找不到文件”(仅此而已)但我仍然想要index.php .
它仅在访问site.com/foo/ 时起作用的原因与第二个.htaccess 无关,它只是webroot/ 默认为其包含的index.php 提供服务。
注意:它在localhost 中工作,localhost 和我现在使用的服务器之间的主要区别可能是该站点在ROOT 中为localhost 但现在在一个子文件夹中 (@987654343 @)。
注意 2:如果我从 index.php/$1 中删除 /$1,它会起作用,它将所有重定向到 index.php,但没有我需要的参数(在上面的示例中为 bar/bar/bar。)
如何让所有请求重定向到带有参数的 index.php?
【问题讨论】:
标签: php apache .htaccess mod-rewrite redirect