问题描述
此Wordpress安装之前的永久链接结构为year/mo/day/post-name
,但后来更改为仅使用帖子名称。 301 RewriteRule已添加到htaccess的顶部,它在大多数情况下都很好用,但在多个链接上仍然失败,将day值保留在URL中。
RewriteRule ([0-9]{4})\/([0-9]{2})\/(.*) domain.com/$3 [R=301,L]
我不知道是什么原因造成的,大多数重定向到了预期的 domain.com/post-name ,但有一些又返回了 domain.com/08/post-name 。
正则表达式是否存在被忽略的问题?
解决方法
如果您所有帖子的格式都相同,如/2020/01/01/post-name
然后尝试使用
RewriteRule ([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/(.*) https://example.com/$4 [R=301,L]
如果您混淆了/2020/01/01/post-name
和/2020/01/post-name
的URL
然后尝试使用
RewriteRule ([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/(.*) https://example.com/$4 [R=301,L]
RewriteRule ([0-9]{4})\/([0-9]{2})\/(.*) https://example.com/$3 [R=301,L]