Swimminginthought

A place for all things technical and my mind..

Menu
  • About Me / Hire Me
Menu

Fixing the WordPress Permalink Structure change Problem and Avoiding 404s

Posted on May 11, 2012 by Percy Kwong

(Oops.. In my haste, I made a boo boo.. I corrected it.. the post is correct now)

It happens to all of us at one time or another.  We decide to change our permalink structure and something / everything breaks in WordPress.  Not because of the fact that we changed the structure, but everybody and everything that linked to our old links are now getting 404 errors (page / content not found).

This is a REALLY BAD THING.  It could seriously hurt your traffic.  So what is one to do?

Support more than one permalink structure!  You can do it in .htaccess by simply using a wonderful tool called regex.

For example, in my case, let’s say I had a link that was:    http://xyz.com/2012/05/foo

(foo being the postname) and I changed the permalink structure to be:

http://xyz.com/foo

It would wreak havoc on my world due to the fact that everyone that linked to /2012/05/foo would get an error.

We fix this by using a regular expression in .htaccess and place it above the ### WordPress Start ### stanza.

Just simply insert the following line:

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.*)$ http://xyz.com/$3

That’s it!  Every request that comes in with a 4 digit number / 2 digit number / postname is permanently redirected to: http://xyz.com/postname

Obviously, you can support all of the default wordpress permalink permutations by using that same concept by placing multiple RedirectMatch 301 lines in there.

Just use what you need and save the computing cycles though.  You should see all your 404 redirect / page / content not found errors go away!   Visitors will still get their content and you get to keep your new permalink structure!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs
  • Resurrection of the Blog
  • Encryption type Matters with Deep Packet Inspection – solved
  • Completely off topic.. Just a personal note.

Recent Posts

  • Kubernetes install gotcha on CentOS-7.x
  • Infrastructure as Code using AWS Cloudformation
  • Does SSL matter? It does and it’s not just web encryption.
  • Apache can’t serve the .well-known directory
  • Cloudy with a chance of Meatballs

Recent Comments

  • Percy Kwong on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Nick Doelman on Boosting Octane Yourself. I did the research, made it, and proved it.
  • Percy Kwong on International Text solutions – A solution
  • Muzahid Ul Islam on The Browser Wars; Which One is Best?
  • Muzahid Ul Islam on International Text solutions – A solution

Archives

  • September 2019
  • August 2019
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • August 2011
  • June 2011
  • March 2011
  • February 2011
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • January 2010
  • November 2009
  • October 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008

Categories

  • Activism
  • All
  • Amazon S3
  • Announcements
  • Apache
  • Apple
  • Applications
  • Automation
  • AWS
  • Azure
  • Backups
  • Blogging
  • Books
  • Bootcamp
  • CentOS – RHEL
  • Cloud Computing
  • Cloudformation
  • Consulting Advice
  • Craigslist
  • Databases
  • Deep Packet Inspection
  • Doing the right thing
  • e-Book Readers
  • E-Mail
  • EC2
  • energy-efficiency
  • environment
  • Expose
  • firewalls
  • General Observations
  • Hardware
  • Hope
  • Hosting
  • IaC
  • Important things to do in life
  • Infrastructure as Code
  • Kubernetes
  • Linux
  • Media and Encoding
  • Miscellany
  • Mobile Phones
  • MySql
  • Networking
  • Performance
  • Personal
  • pfsense
  • Politics
  • Privacy
  • Redundancy
  • Routers
  • security
  • SPAM
  • Tech that doesn't work like it should
  • Tips and Tricks
  • Tools that work
  • Tout
  • Video
  • Virtual Computing
  • VOIP-Voice Over IP
  • VPN
  • Web Browsers
  • Web Hosting
  • Websites
  • Windows
  • Wordpress

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2026 Swimminginthought | Built using WordPress and Responsive Blogily theme by Superb