简体   繁体   English

PHP只允许访问某个文件?

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

how can i show only the index.php and ignore any other calls to other php files, so if i were to go to somefile.php, the page would stay at index.php all the time, however if i were to go to index.php?get=somefile it would then allow you to execute that. 我如何只显示index.php而忽略对其他php文件的任何其他调用,所以如果我要转到somefile.php,则该页面将始终停留在index.php上,但是如果我要去索引.php?get = somefile,它将允许您执行该操作。

so in short i only want the index.php to be the main caller and executor of everything and to ignore any calls to any other php files that is not index.php. 简而言之,我只希望index.php是所有内容的主要调用者和执行者,并且忽略对不是index.php的任何其他php文件的任何调用。

i have this in my .htaccess. 我在我的.htaccess文件中有此文件。

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

it does everything i'm asking for but it dosen't let you call any php file using get in index.php like index.php?get=somefile 它完成了我要的所有操作,但它不允许您使用index.php?get=somefile类的index.php?get=somefile来调用任何php文件index.php?get=somefile

where is it going wrong and how do i correct it? 哪里出错了,我该如何纠正?

You are not rewriting the get parameter. 您没有重写get参数。 Try this: 尝试这个:

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

Right Now your htaccess code is creating a url of: 现在,您的htaccess代码正在创建以下网址:

index.php/somefile.php

Add

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

From here you can do two things 从这里您可以做两件事

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

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

2) Add another RewriteRule: 2)添加另一个RewriteRule:

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

Depending on your server setup you may need to change index.php?get=$1 to one of the following 根据您的服务器设置,您可能需要将index.php?get = $ 1更改为以下内容之一

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

Then on your index.php page you would include the page passed by the $_GET['get'] variable. 然后,在index.php页面上,您将包含$ _GET ['get']变量传递的页面。

Here's your final rule, tell me if it works: 这是您的最终规则,请告诉我它是否有效:

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

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

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

So if you went to site.com/?get=asdf , you could access that via $_GET['get'] in your index.php file. 因此,如果您访问site.com/?get=asdf ,则可以通过index.php文件中的$_GET['get']进行访问。

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

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