我怎么能只显示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=somefile
哪里出错了,我该怎么纠正呢?
答案 0 :(得分:0)
您没有重写get参数。试试这个:
RewriteRule ^(.*)$ index.php?get=$1
答案 1 :(得分:0)
现在您的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']变量传递的页面。
答案 2 :(得分:0)
这是你的最终规则,告诉我它是否有效:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?get=$1 [QSA,L]
答案 3 :(得分:-2)
http://wiki.apache.org/httpd/RewriteFlags/QSA
RewriteRule ^(.*)$ index.php/$1 [QSA]
因此,如果您转到site.com/?get=asdf
,则可以通过$_GET['get']
文件中的index.php
访问该文件。