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/