我将 WordPress 永久链接结构从 %year%/%months%/ 更改为 %postname%

所以我创建了这个 mod 别名规则 .htaccess 但我有一个问题:

RedirectMatch 301 /\d{4}/\d{2}/([^/]+)(/?)(.*)$ http://domainname.com/$1

该规则还重定向了 wp-content 目录下的图像,因此 域名.com/wp-content/uploads/2013/11/name.jpg 变得 域名.com/name.jpg

我无法使用 RewriteCond 因为这个 RedirecMatch 是 mod_alias,我尝试使用 !^/(wp-content.*)$ 但不起作用。

我该如何解决?使用RedirectMach或RewriteRule更好(我没有更改服务器)?

你可以发布一个 更好的正则表达式?

谢谢你!

有帮助吗?

解决方案

您应该使用mod_rewrite而不是mod_alias坚持,因为它会干扰wordpress'mod_rewrite规则。mod_rewrite和mod_alias都会影响URL文件处理管道的不同点的相同请求URI,因此您最终可能会在同时重定向和重写。

RewriteCond %{REQUEST_URI} !\.(jpeg|gif|png)$ [NC]
RewriteRule ^\d{4}/\d{2}/([^/]+?)(/?)(.*)$ http://domainname.com/$1 [L,R=301]
.

其他提示

尝试 ^$:

RedirectMatch 301 ^/\d{4}/\d{2}/([^/]+)(/?)(.*)$ http://domainname.com/$1
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top