可以帮助我,我尝试删除我的 url 上的 .html 扩展名,但仍然不起作用。
这是我的.httaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
</IfModule>
请注意,使用
RewriteRule ^ index.php [QSA,L]
你的规则只是重写index.php
而不是所有*.html
如果您只想删除网址末尾的
.html
,您只需要在您的.htaccess
中使用它:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule (.*) $1.html [L]
但请注意,这不会将用户从
https://example.com/page.html
重定向到https://example.com/page
例如:您必须将所有锚标签 href 值从
<a href="https://example.com/page.html">Link</a>
替换为 <a href="https://example.com/page">Link</a>
如果你想了解更多关于
.htaccess
以及你可以用它做什么,我推荐你这篇文章。