[英].htaccess rewrite root directory forbidden
I have a document structure in which I have a .htaccess
file in the parent directory called Fort
. 我有一个文档结构,其中在名为
Fort
的父目录中有一个.htaccess
文件。 In that same directory, I have a folder named public
. 在同一目录中,我有一个名为
public
的文件夹。 I have in that public
directory a bootstrap.php
script. 我在该
public
目录中有一个bootstrap.php
脚本。
Here is my .htaccess
code: 这是我的
.htaccess
代码:
RewriteEngine On
RewriteBase /Fort
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ bootstrap.php?url=$1 [QSA,L]
I am using mamp and the default url is set to localhost:8888/Fort/
. 我使用的是Mamp,默认网址设置为
localhost:8888/Fort/
。
My bootstrap.php
script has this code: 我的
bootstrap.php
脚本具有以下代码:
<?php
echo $_GET['url'];
For some reason when I pass a url say localhost:8888/Fort/foo/bar
, my bootstrap.php
script returns the url as foo/bar
. 出于某种原因,当我传递一个URL时说
localhost:8888/Fort/foo/bar
,我的bootstrap.php
脚本将该URL返回为foo/bar
。 But if I pass the url localhost:8888/Fort/
, I get a 403 Forbidden
error, and the bootstrap.php
script is not loaded. 但是,如果我通过url
localhost:8888/Fort/
,则会收到403 Forbidden
错误,并且没有加载bootstrap.php
脚本。
Good question! 好问题! Thanks for all the info.
感谢您提供所有信息。
Change the last line to this: 将最后一行更改为此:
RewriteRule ^(.*)$ bootstrap.php?url=$1 [QSA,L]
When you visit /Fort/
there is an empty string for the rewrite to match, and you were matching +
which means one or more characters, when there are in fact no characters, so it wasn't getting triggered. 当您访问
/Fort/
有一个空字符串供重写匹配,并且您正在匹配+
,表示一个或多个字符,而实际上没有字符,因此不会被触发。 Changing to *
says zero or more characters which fixes the problem and will now match /Fort/
as expected. 更改为
*
表示零个或多个字符可以解决问题,并且现在可以按预期与/Fort/
匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.