我想在.htaccess文件中放一些东西,以隐藏.phpphp文件的文件扩展名,因此转到www.example.com/dir/somepage会显示它们www.example.com/dir/somepage.php。
.htaccess
.php
有什么可行的解决方案吗?我的网站使用HTTPS(如果很重要)。
这是我目前的.htaccess:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] ErrorDocument 404 /error/404.php RewriteCond %{REQUEST_FILENAME}.php -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.php [L]
在您的.htaccess中在DOCUMENT_ROOT下使用以下代码:
Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L,NC] ## To internally redirect /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME}.php -f [NC] RewriteRule ^ %{REQUEST_URI}.php [L]