内容页清洁网址设置

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>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值