繁体   English   中英

PHP只允许访问某个文件?

[英]php only allow access to a certain file?

我如何只显示index.php而忽略对其他php文件的任何其他调用,所以如果我要转到somefile.php,则该页面将始终停留在index.php上,但是如果我要去索引.php?get = somefile,它将允许您执行该操作。

简而言之,我只希望index.php是所有内容的主要调用者和执行者,并且忽略对不是index.php的任何其他php文件的任何调用。

我在我的.htaccess文件中有此文件。

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

它完成了我要的所有操作,但它不允许您使用index.php?get=somefile类的index.php?get=somefile来调用任何php文件index.php?get=somefile

哪里出错了,我该如何纠正?

您没有重写get参数。 尝试这个:

RewriteRule ^(.*)$ index.php?get=$1

现在,您的htaccess代码正在创建以下网址:

index.php/somefile.php

RewriteCond %{REQUEST_URI} !^index.php.*

从这里您可以做两件事

1)将RewriteRule ^(。*)$ index.php / $ 1更改为:

RewriteRule ^(.*)$ index.php?get=$1

2)添加另一个RewriteRule:

RewriteRule ^index.php/(.*)$ index.php?get=$1 [L]

根据您的服务器设置,您可能需要将index.php?get = $ 1更改为以下内容之一

./index.php?get=$1
http://yourdomain.com/index.php?get=$1

然后,在index.php页面上,您将包含$ _GET ['get']变量传递的页面。

这是您的最终规则,请告诉我它是否有效:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?get=$1 [QSA,L]

http://wiki.apache.org/httpd/RewriteFlags/QSA

RewriteRule ^(.*)$ index.php/$1 [QSA]

因此,如果您访问site.com/?get=asdf ,则可以通过index.php文件中的$_GET['get']进行访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM