0

My site was first built with html/css in 2000, and when I rebuilt it with WordPress in 2012, I kept the .html extension in the interest of keeping the same URLs. I'd like to get rid of it now and redirect the old html pages to the new extension-less pages.

My current permalink structure is: /%category%/%postname%.html

I'd like it to be: /%category%/%postname%

To do that, I tried deleting ".html' from the end of the permalink structure, then saving permalinks. Then, I put this in my .htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

But it doesn't work -- pages just give me 404 errors that way.

I took a look at the Yoast permalink redirection tool, but that only redirects to /%postname% -- I'm not sure if it's possible to modify the outputted rule to add the category before the postname.

0

It sounds like you didn't flush your permalinks. Remove what you wrote in your .htaccess. Set what you had that was working before in the custom section of the permalink settings %category%/%postname%.html, save it, select 'plain', save it, then change it to your new settings %category%/%postname% save it, select 'plain', save it, then go to your custom setting and it should work.

  • Thanks, Gregory! Do I add the 301 .htaccess redirection back afterwards? I'd like to make sure that Google understands that the old addresses have moved. – quantaws Sep 23 '17 at 21:14
  • Either add 301 redirects to .htaccess or have Google reindex your site through webmaster tools. – Gregory Schultz Sep 23 '17 at 21:30
  • Thanks. The new permalink structure works (afer flushing), but the old URLs don't redirect to the new, they just return 404s. I added the rewrite rule back to .htaccess but still get 404s. – quantaws Sep 23 '17 at 21:42
  • Finally figured it out; needed the rewrite rule but not the one above. – quantaws Sep 23 '17 at 21:55
0

OK. I finally got it done. Here's what I did: (1.) changed the WordPress permalink structure to /%category%/%postname% and saved.

(2.) Added this to .htaccess: RewriteRule (.+).html?$ https://example.com/$1 [R=301,L] (The rewrite rule in my original question didn't work for me.)

Now the .html URLs are redirecting to the new extensionless URLs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.