亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

.htaccess 仍然允許訪問文件

.htaccess 仍然允許訪問文件

PHP
江戶川亂折騰 2023-07-08 20:13:52
如果我想阻止隨機用戶使用 URL 瀏覽 Web 文件,我需要使用 .htaccess 文件。我在下面添加了我的代碼。我創建了一個 .htaccess 文件并將其放置在我的 include 文件夾中,以防止用戶導航到并讀取我的 database.php 文件。當然我做了一些細微的修改。這是我的 .htaccess 文件中的代碼:<files?database.php> Order?Allow,Deny Deny?from?all </files>使用上面的內容,我仍然能夠直接訪問 database.php 文件。我需要阻止這種情況發生。我究竟做錯了什么?
查看完整描述

2 回答

?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

請檢查以下內容:

  1. 確保您的 .htaccess 文件確實名為“.htaccess”

  2. .htaccess 文件必須位于正確的目錄中,或者文件的路徑必須相對于 .htaccess 文件。

我剛剛在我的機器上運行了這個。您使用過的相同代碼。我的結構:

http://img2.sycdn.imooc.com/64a95321000125b402670109.jpg

這些文件是相同的。我注釋掉了根目錄中的 .htaccess 文件中的內容。所以現在我可以打電話localhost:8080/database.php,但不能localhost:8080/test/database.php=>我收到Error 403(訪問被拒絕)。

編輯

這里的指南怎么樣??設置 htaccess

看起來合法。這是我的配置。根據指南,這只是設置此配置文件并重新啟動。

http://img1.sycdn.imooc.com/64a9532f0001973406470156.jpg

編輯2


我發現我打開的 httpd.conf 不正確。我在下面找到了正確的一個:Application/XAMPP/xamppfiles/etc/httpd.conf.


在此文件中,您必須搜索:


#?

# DocumentRoot: The directory out of which you will serve your

# documents. By default, all requests are taken from this directory, but

# symbolic links and aliases may be used to point to other locations.

#

DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"

<Directory "/Applications/XAMPP/xamppfiles/htdocs">

? ? #

? ? # Possible values for the Options directive are "None", "All",

? ? # or any combination of:

? ? #? ?Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

? ? #

? ? # Note that "MultiViews" must be named *explicitly* --- "Options All"

? ? # doesn't give it to you.

? ? #

? ? # The Options directive is both complicated and important.? Please see

? ? # http://httpd.apache.org/docs/trunk/mod/core.html#options

? ? # for more information.

? ? #

? ? #Options Indexes FollowSymLinks

? ? # XAMPP

? ? Options Indexes FollowSymLinks ExecCGI Includes


? ? #

? ? # AllowOverride controls what directives may be placed in .htaccess files.

? ? # It can be "All", "None", or any combination of the keywords:

? ? #? ?Options FileInfo AuthConfig Limit

? ? #

? ? #AllowOverride None

? ? # since XAMPP 1.4:

? ? AllowOverride All


? ? #

? ? # Controls who can get stuff from this server.

? ? #

? ? Require all granted

</Directory>

在這里你可以找到這個:


#AllowOverride None? # this does deactivate .htaccess

# since XAMPP 1.4:

AllowOverride All? ? # this does activate .htaccess

至少對我來說,這完全負責 .htaccess 重寫。當我將其設置為AllowOverride None 時,.htaccess 被完全忽略。


查看完整回答
反對 回復 2023-07-08
?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

您可以使用mod_rewrite站點根 .htaccess 中的規則來執行此操作:


RewriteEngine On


RewriteCond %{THE_REQUEST} /database\.php[?\s/] [NC]

RewriteRule ^ - [F]


查看完整回答
反對 回復 2023-07-08
  • 2 回答
  • 0 關注
  • 204 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號