1
votes

How can I redirect a Wordpress permalink from

example.com/%year%/%monthnum%/%postname%.html

to

example.com/%postname%

I have tried doing it through a plugin and also by adding the following code to .htaccess file but it's returning 404 not found error.

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

1 Answers

0
votes

Try this in your .htaccess file:

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

Make sure it is above the default WordPress rewrite rules.

E.g.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

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

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

# END WordPress