重定向 Wordpress 永久链接

Redirecting Wordpress permalink

如何从

重定向 Wordpress 永久链接
example.com/%year%/%monthnum%/%postname%.html

example.com/%postname%

我试过通过一个插件来完成,也尝试将以下代码添加到 .htaccess 文件,但它返回 404 not found 错误。

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.*)$ http://www.example.com/

在您的 .htaccess 文件中试试这个:

RewriteRule ^[0-9]{4}/[0-9]{2}/(.*)\.html$ / [R=301,L]

确保它高于默认的 WordPress 重写规则。

例如

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^[0-9]{4}/[0-9]{2}/(.*)\.html$ / [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress