1.栏目里文章命名规则去掉.html
2.在.htaccess里加上
RewriteEngine On
# 排除后台路径,确保后台页面不受影响
RewriteCond %{REQUEST_URI} !^/dede/ [NC]
# 针对 /tag/ 路径单独处理,保留 .html 扩展名
RewriteRule ^tag/([a-zA-Z0-9_]+)/?$ /tag/$1.html [L]
# 避免对首页的重写,防止重定向循环
RewriteCond %{REQUEST_URI} ^/index$ [NC]
RewriteRule ^index$ /index.php [L]
# 取消内容页面的文件扩展名 (.html),但避免再次触发重写
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !\.html$ [NC]
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)$ $1/$2.html [L]
# 强制重定向到清洁URL,但避免已清洁URL再次触发
RewriteCond %{THE_REQUEST} \s/([^.]+)\.html [NC]
RewriteCond %{REQUEST_URI} !^/dede/ [NC]
RewriteCond %{REQUEST_URI} !/tag/ [NC]
RewriteRule ^ /%1 [R=301,L]
# 确保末尾斜杠的路径不会导致循环
RewriteCond %{REQUEST_URI} !^(.+)/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
在 Apache 服务器上,需要告诉服务器如何处理没有扩展名的文件。你可以在 .htaccess 文件中添加以下配置:
<FilesMatch "^[^.]+$">
ForceType application/x-httpd-php
</FilesMatch>