Remove year and month in URL using .htaccess

For example, to redirect old URLs of the form:

/2016/10/mukunda-murari-kannada-songs-download.html

To

/mukunda-murari-kannada-songs-download.html

I have already changed the permalink structure in WordPress, but wish to redirect the old URLs to the new, in the most efficient way, in order to help preserve SEO.

This is my code:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ $1.html [L,R=301]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

2 Answers
2

Assuming you have already changed the permalinks structure as @RickHellewell suggests, then you can do something like the following near the top of your .htaccess file (before the existing WP front-controller) to redirect the old URLs (with the stated format) in order to preserve SEO.

RewriteRule ^\d{4}/\d\d/([a-z-]+\.html)$ /$1 [R=301,L]

Leave a Comment