Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.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只允许访问某个文件?_Php_Mod Rewrite - Fatal编程技术网

php只允许访问某个文件?

php只允许访问某个文件?,php,mod-rewrite,Php,Mod Rewrite,我怎样才能只显示index.php而忽略对其他php文件的任何其他调用,因此如果我转到somefile.php,页面将始终停留在index.php,但是如果我转到index.php?get=somefile,它将允许您执行该操作 因此,简而言之,我只希望index.php成为所有事情的主要调用方和执行者,并忽略对任何其他非index.php的php文件的调用 我的.htaccess中有这个 RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-f R

我怎样才能只显示index.php而忽略对其他php文件的任何其他调用,因此如果我转到somefile.php,页面将始终停留在index.php,但是如果我转到index.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调用任何php文件,比如index.php?get=somefile


哪里出错了?如何更正?

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

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

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

现在,您的htaccess代码正在创建一个url:

index.php/somefile.php

从这里你可以做两件事

1将重写规则^.*$index.php/$1更改为:

RewriteRule ^(.*)$ index.php?get=$1
2添加另一条规则:

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页面上,您将包含由$\u GET['GET']变量传递的页面。

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

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

那么,你是说如果有人转到index.php?get=somefile,你希望它重定向到somefile.php,还是希望它保留在index.php上,但包含somefile.php的内容?所有内容都将保留在index.php上,它将包括任何被调用文件的内容,他曾声明希望site.com/somefile.php被重定向到index.php?get=somefile.php。如果有人将somefile.php?var=test放入QSA。它将成为site.com/index.php/somefile.php?var=test,但没有其他规则,服务器很可能会返回Page Not FoundOP。简言之,我只希望index.php成为所有内容的主要调用方和执行者,并忽略对任何其他非index.php的php文件的调用。该重写规则将通过index.php发送所有内容,他可以使用include或类似的方法在过滤LFI/RFI后执行$_GET['GET']。OP确实说过,但您的重写规则将导致大部分时间找不到页面,或者由于不正确的规则集,导致结构不正确的index.php页面。找不到css/includes/js。我试过你的,这就是为什么我的答案中有一个额外的规则。我在发帖前就试过了。你的QSA错了。QSA的意思是:应用规则,然后,一旦它被应用,如果在应用规则之前URL的GET中有什么东西,那么再次将它添加到重写的URL中。因此,如果您通过site.com/test/?aa=asdf访问站点并应用^.*$index.php/$1,那么:1没有QSA,最终URL将是index.php/test/,2有QSA,您将得到index.php/test/?aa=asdf@JamesWilliams是的,但这就是我应该在我的答案中包含的两行重写的原因。他们会阻止404@OlivierPons看到了我之前的评论。OP希望index.php处理所有事情-site.com/test/?aa=asdf仍将激发index.php。URL的测试部分可以通过$\u服务器['REQUEST\u URI']访问。
./index.php?get=$1
http://yourdomain.com/index.php?get=$1
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?get=$1 [QSA,L]