首页 > 解决方案 > 如何在 .htaccess 中使用一行代码隐藏 php 扩展

问题描述

我想问的是,不要在 .htaccess 中写很多行,包括所有页面来隐藏它们的扩展名,比如

RewriteRule ^about$ about.php [L]
RewriteRule ^register$ register.php [L]
RewriteRule ^login$ login.php [L]
RewriteRule ^dashboard$ dashboard.php [L]
RewriteRule ^logout$ logout.php [L]

是否有任何单行代码可以做到这一点?

标签: php.htaccesshidefile-extension

解决方案


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

推荐阅读