我想从网站的所有url中删除.html
,我正在处理x-cart,并希望使用.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>
我使用了这个代码,但它不起作用
使用类似:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)/?$ $1.html [NC,L]
您可以使用:
# remove html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).html [NC]
RewriteRule ^ %1 [R=301,L]
# add html but only if file exist with html and not without
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
您可以使用它来隐藏.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*.html$ %{REQUEST_FILENAME}.html [L]