我正在尝试删除页面扩展名并使用此方法:
方法1:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
方法2:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
但是使用这些方法我只能删除php扩展! 如何删除html和php扩展?
答案 0 :(得分:0)
您可以使用此
RewriteEngine on
# remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ $1.php [L]
#remove .html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/?$ $1.html [L]
答案 1 :(得分:-1)
只需使用:
RewriteEngine on
RewriteRule ^(.*).html$ http://your-domain.tld/$1 [R=301,L]
RewriteRule ^(.*).php$ http://your-domain.tld/$1 [R=301,L]
有关详细信息,请参阅:https://htaccessbook.com/add-remove-change-file-extensions-htaccess/