Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php .htaccess重写规则导致;“未找到文件”;_Php_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php .htaccess重写规则导致;“未找到文件”;

Php .htaccess重写规则导致;“未找到文件”;,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我的网站位于子文件夹中:site.com/foo/ 在foo/文件夹的根目录中,我有以下.htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule (.*) webroot/$1 [L] </IfModule> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f

我的网站位于子文件夹中:
site.com/foo/

foo/
文件夹的根目录中,我有以下
.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule (.*) webroot/$1 [L]
</IfModule>
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
,我得到了“未找到文件”(仅此而已),但我想要
index.php

它只在访问
site.com/foo/
时起作用的原因与第二个
.htaccess
无关,它只是在默认情况下为其包含的index.php提供
webroot/
服务

注意:它在
localhost
中工作,
localhost
和我现在使用的服务器之间的主要区别可能是站点位于
localhost
ROOT
中,但现在位于子文件夹中(
foo/

注意2:如果我从
index.php/$1
中删除
/$1
,它会工作,它会将所有内容重定向到index.php,但没有我需要的参数(
bar/bar/bar


如何将所有请求重定向到带有参数的index.php

尝试在两者中添加
RewriteBase
。htaccess:

/foo/.htaccess:

RewriteEngine On
RewriteBase /foo/

RewriteRule (.*) webroot/$1 [L]
RewriteEngine On
RewriteBase /foo/webroot/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php/$1 [L]
/foo/webroot/.htaccess:

RewriteEngine On
RewriteBase /foo/

RewriteRule (.*) webroot/$1 [L]
RewriteEngine On
RewriteBase /foo/webroot/

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

QSA标志附加查询字符串-


RewriteRule(.*)index.php?data=$1[QSA]

浏览器中的完整URL是什么?您得到了什么错误?URL是“site.com/foo/bar/”,我得到的是“未找到文件”。它在不通过
/foo/.htaccess
中的index.phpTo测试更改规则的情况下查找该url,以
重写规则(.*)webroot/$1[L,R]
,然后加载
site.com/foo/bar
,这将重定向到(secret)/www/foo/webroot/bar。。。它似乎真的没有考虑index.php,为什么在
/foo/
之前有
/www/
?我以为你的网页根是
/www/