我可以从url中删除.php扩展名,但我想如果用户输入带.php扩展名的网址,那么页面应该使用.htaccess显示404错误
任何帮助请
答案 0 :(得分:1)
您可以将此代码放入DOCUMENT_ROOT/.htaccess
文件中以隐藏.php
扩展程序:
RewriteEngine On
RewriteBase /
# To externally redirect /file.php to /file
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
# To internally forward /file to /file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
答案 1 :(得分:0)