2015-04-07 23 views
0

我的网站是一个子文件夹托管:site.com/foo/的.htaccess重写规则造成“找不到文件”

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之间的主要区别,我现在使用的服务器可能是该网站在ROOTlocalhost但现在子文件夹内(foo/)。

注意2:如果我从index.php/$1删除/$1,它的工作原理,它重定向到所有的index.php,但没有我需要的参数

我怎样才能得到所有请求(在上面的例子bar/bar/bar)。被重定向到index.php的参数?

回答

0

尝试在双方的.htaccess添加RewriteBase

/foo/.htaccess:

RewriteEngine On 
RewriteBase /foo/ 

RewriteRule (.*) webroot/$1 [L] 

/foo/webroot/.htaccess:

RewriteEngine On 
RewriteBase /foo/webroot/ 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (.*) index.php/$1 [L] 
+0

我actualy试过了精确解,结果是:一模一样... – lapin

+0

什么是浏览器的完整URL,什么错误做你得到? – anubhava

+0

URL是“site.com/foo/bar/”,我得到的是“找不到文件”。它会在没有经过index.php – lapin

-1

QSA标志附加查询字符串 -

(。*)?

重写规则的index.php数据= $ 1 [QSA]