2 回答

TA貢獻1772條經驗 獲得超8個贊
請檢查以下內容:
確保您的 .htaccess 文件確實名為“.htaccess”
.htaccess 文件必須位于正確的目錄中,或者文件的路徑必須相對于 .htaccess 文件。
我剛剛在我的機器上運行了這個。您使用過的相同代碼。我的結構:
這些文件是相同的。我注釋掉了根目錄中的 .htaccess 文件中的內容。所以現在我可以打電話localhost:8080/database.php
,但不能localhost:8080/test/database.php
=>我收到Error 403
(訪問被拒絕)。
編輯
這里的指南怎么樣??設置 htaccess
看起來合法。這是我的配置。根據指南,這只是設置此配置文件并重新啟動。
編輯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 被完全忽略。

TA貢獻1875條經驗 獲得超3個贊
您可以使用mod_rewrite站點根 .htaccess 中的規則來執行此操作:
RewriteEngine On
RewriteCond %{THE_REQUEST} /database\.php[?\s/] [NC]
RewriteRule ^ - [F]
- 2 回答
- 0 關注
- 204 瀏覽
添加回答
舉報