2012-03-28 169 views
1

我怎么能只显示index.php并忽略任何其他的PHP文件的其他调用,所以如果我要去somefile.php,页面会留在index.php所有的时间,但是如果我要去到index.php?get = somefile它会允许你执行它。php只允许访问某个文件?

因此总之我只想让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任何PHP文件是它要去的地方错误的,如何纠正呢?

+0

所以你是说,如果有人去的index.php GET = somefile你想让它重定向到somefile.php或者你要吗?保持index.php,但包括somefile.php的内容? – TheOx 2012-03-28 02:50:09

+0

一切都会保留在index.php上,它将包含任何被调用文件的内容 – codrgi 2012-03-28 02:53:02

回答

0

您不重写get参数。试试这个:

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

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

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

所以,如果你去site.com/?get=asdf,你可以访问通过$_GET['get']index.php文件。

+0

他表示他希望将site.com/somefile.php重定向到index.php?get = somefile.php。有了QSA,如果有人把somefile.php?var = test。这将成为site.com/index.php/somefile.php?var=test,但没有其他规则的服务器将返回更多的可能“页面未找到” – 2012-03-28 03:07:24

+0

OP说“所以总之我只想index.php成为一切的主要调用者和执行者,并忽略对任何不是index.php的其他php文件的调用。“ 该重写规则将通过index.php发送所有内容,并且他可以使用include()或类似的命令执行$ _GET ['get'](在过滤LFI/RFI后) – yrosen 2012-03-28 03:21:08

+0

OP确实说过,但是您的重写规则将导致“页面未找到”(大多数时间)或index.php页面的结构不正确,由于不正确的规则设置不能找到css/includes/js。我已经尝试过你的这就是为什么我有一个附加规则在我的回答中,我在发帖之前试过了 – 2012-03-28 03:24:48

0

现在你的htaccess代码创建的网址:

index.php/somefile.php 

添加

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

从这里你可以做两件事情

1)更改重写规则^(*) $ index.php/$ 1至:

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

2)添加其他重写规则:

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

根据您的服务器设置,你可能需要改变的index.php获得= $ 1以下

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

之一,那么你的index.php页面上?你会包含$ _GET ['get']变量传递的页面。

0

这是你的最终规则,告诉我,如果它的工作原理:

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