PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] Redirecting old .html page to new without html extension page?

 February 17, 2022     .htaccess, html, redirect, wordpress     No comments   

Issue

I've just changed permalinks in my wordpress site.

And my old links were like that,

http://www.sitename.com/category/postname.html

Now new links are

http://www.sitename.com/category/postname/

I'm getting 404 error at old links, how can i redirect all .html pages to new non .html pages with .htaccess?


Solution

In the htaccess file in your document root, add these before your wordpress rules:

RedirectMatch 301  ^/([^/]+)/([^/.]+)\.html$ /$1/$2/
RedirectMatch 301  ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/

Of if you need to limit it by hosts, you can use mod_rewrite:

RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/.]+)\.html$ /$1/$2/ [R=301,L]

RewriteCond %{HTTP_HOST} sitename.com [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ [R=301,L]


Answered By - Jon Lin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing