[英]Index.php still accessible after changing it to index in .htaccess
實際網址www.example.com/index.php
重新編寫腳本以刪除.php后,它變為www.example.com/index
。 唯一的問題是www.example.com/index.php
仍然可以訪問。 如何擺脫這個? 重寫規則以刪除我使用的.php。
**RewriteRule ^index$ index.php [NC,L]**
這是另一回事:RewriteEngine將用戶提供的URL轉換為可以訪問的本地文件(簡化版本)。
如果用戶打開“ http://example.com/test ”,重寫引擎將通過添加擴展名將其轉換為“ test.php”。
我假設您希望用戶永遠不會在瀏覽器中看到“ .php”,所以這是一個解決方案:
RewriteEngine On
# If is has php extension,
# let browser redirect to non-php version
RewriteRule ^(.*)\.php$ /$1 [L,END,R]
# If the file does not exist, add php extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L,END]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.