Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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';无法使用Slimframework访问_Php_.htaccess_Slim - Fatal编程技术网

防止';php';无法使用Slimframework访问

防止';php';无法使用Slimframework访问,php,.htaccess,slim,Php,.htaccess,Slim,我正在为我的web应用程序使用Slimframework&我的所有url请求都指向'index.php'中的一个入口点,使用my.htaccess中的以下重写: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [QSA,L] 一切正常,但是,index.php仍然可以通过以下请求/路由在url中访问: /mywebsi

我正在为我的web应用程序使用Slimframework&我的所有url请求都指向'index.php'中的一个入口点,使用my.htaccess中的以下重写:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
一切正常,但是,
index.php
仍然可以通过以下请求/路由在url中访问:
/mywebsite/public/index.php
这是我不想要的。现在我知道它是我的公共html文件夹中唯一的文件,但我不想在url中访问它。。。我如何将其重定向到错误的路线

1) .htaccess重写

2) 一些细微的逻辑


如果要禁用对index.php的外部访问,请将以下代码置于现有规则之上

RewriteEngine on

RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
RewriteRule ^ - [F]

如果直接访问/index.php,则返回禁止的错误

您可以这样更新规则:

RewriteEngine on
# Rewrite to index.php
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^ index.php [L,E=rewritten:1]
# 404 any direct access of index.php
RewriteCond %{ENV:rewritten} !=1
RewriteCond %{ENV:REDIRECT_rewritten} !=1
RewriteRule ^index\.php$ - [R=404,L]
我移除了不需要的QSA标志。我删除了不必要的文件和目录检查,代之以更快的
index.php
检查


为了回答您的实际问题,对于任何直接访问index.php的尝试,我将返回404。另一种选择是重定向到某个位置。

这很好,但与其返回禁止的错误,我如何将其重定向到特定的路径?i、 e:RewriteRule^-www.mysite.com/error/errorshow我会重定向到特定的路由吗?而不仅仅是404禁止页面,即:RewriteRule^-www.mysite.com/error/error您可以使用
ErrorDocument 404/error/errors
,这样就可以用作错误页面。或者我可以更新代码重定向到那个。让我知道。