簡體   English   中英

將它更改為.htaccess中的索引后,仍可訪問Index.php

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM