1 回答

TA貢獻1111條經驗 獲得超0個贊
您發布的方法完全符合您的要求。您在文件系統上有一個“index.php”文件,您的 URL 類似于“www.mysite.com/index”(URL 中沒有 .php 擴展名)。
RewriteEngine on
# The requested filename "/index" is not a directory
RewriteCond %{REQUEST_FILENAME} !-d
# There is a file on the file system named as the request, with extension .php
RewriteCond %{REQUEST_FILENAME}.php -f
# If all of the above is true, pretend that the ".php" file had been called
# by rewriting the request appending .php
RewriteRule ^(.*)$ $1.php
您不需要將“index.php”重命名為“index”。
如果您還想在指定 .php 時阻止訪問,請將此規則放在上面的規則之前?,F在,“mysite/index”可以工作,“mysite/index.php”不會。
# Return 404 if original request is .php
RewriteCond %{REQUEST_FILENAME} "\.php$"
RewriteRule .* - [L,R=404]
請注意,還有其他幾種方式可能會讓人意識到您的網站使用 PHP,而 php-to-404 規則沒有多大意義。
- 1 回答
- 0 關注
- 117 瀏覽
添加回答
舉報