3 回答
TA贡献1875条经验 获得超5个赞
您可以像这样从请求中删除.php
RewriteCond %{REQUEST_URI} ^/(.*).php$
RewriteRule ^(.*)$ %1 [L,QSA]
TA贡献1803条经验 获得超6个赞
码
RewriteEngine On
RewriteBase /
# remove enter code here.php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
TA贡献1825条经验 获得超4个赞
您还可以将以下代码放入.htaccess文件中:
options +multiviews
这是在当前目录中搜索可用的扩展名(我认为是.html,.htm和.php)。因此,例如,如果您请求/user它将查找user.php。
- 3 回答
- 0 关注
- 586 浏览
添加回答
举报