[英]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.