我正在尝试从URL中删除php扩展名,删除了php,但是执行代码时未读取所有php代码/文件。下面是代码
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php
[NC]
RewriteRule ^ %1 [R,L,NC]
# remove index
RewriteRule (.*)index$ $1 [R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
答案 0 :(得分:0)
在.htaccess文件中添加以下代码
RewriteEngine开启
RewriteCond%{REQUEST_FILENAME} .php -f
RewriteRule!。*。php $%{REQUEST_FILENAME} .php [QSA,L]
注意:在Godaddy服务器上,要删除扩展名,您需要先启用MultiViews。以下是相同的代码
选项+多视图
RewriteEngine开启
RewriteCond%{REQUEST_FILENAME} .php -f
RewriteRule!。*。php $%{REQUEST_FILENAME} .php [QSA,L]