I am having an issue on a WordPress-based website I run regarding a Rewrite Rule in my .htaccess file.
Recently overhauled the website and my permalink structure has changed. Previously, it was
/%year%/%monthnum%/%postname%.html
Now, it is
/%year%/%monthnum%/%postname%/
The issue I'm running into is Google having all the .html links stored. So, visitors who follow the links via Google get a 404.
What I would like to happen is that anytime an incoming URL has the .html on the end and matches the permalink structure format, redirect to the same URL, just without the html extension.
I tried adding a Rewrite Rule to my .htaccess file and am having issues with it not working. I'm not sure what that issue is.
RewriteEngine On
RewriteBase /mywebsite.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]{4}+)/([0-9]{2}+)/([a-zA-Z0-9-]+).html$ $1/$2/$3/
You're close but your regex is little bit off track. Try this rule:
RewriteEngine On
RewriteBase /mywebsite.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]{4})/([0-9]{2})/(.+?)\.html$ $1/$2/$3/ [L,NC,NE,R=301]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With