I converted my website to WordPress. In the process, in order to satisfy WordPress’s rules about permalink formats, I had to change the filenames from ending in .html to ending in -html.
Unfortunately, there are backlinks from other sites that point to the old pages that end in .html. So when someone clicks one of those backlinks, the page cannot be found on the new site.
For this reason, I want to permanently redirect all requests for URIs ending in .html using .htaccess so that they end instead with -html.
So for instance:
https://example.com/file1.html
needs to permanently redirect to
https://example.com/file1-html
Sadly, my code generates 500 errors.
Here’s what I wrote based upon what I found in the Apache manual:
<Directory /home/accountname/public_html>
RewriteEngine on
RewriteBase /home/accountname/public_html
RewriteCond $1.html !-f
RewriteRule ^(.*).html$ $1-html [R=301,L]
</Directory>
Can someone help?
<Directory>
directive isn’t allowed in .htaccess.Place this rule in your main WP .htaccess:
Make sure this is first rule below
RewriteEngine on
line.