[resolved] Permalink Rewrite (5 posts)

  1. Michael Moore
    Posted 3 years ago #

    I'm currently using the permalink structure /%category%/%postname%.html. But, I have tons of hard coded links to posts from a previous permalink structure of /%year%/%postname%. Currently, http://www.url.com/2009/post-name.html works but http://www.url.com/2009/post-name does not. Can anyone point me in the write direction as to how to make that sturcture work, or to append .html onto posts with the structure?

  2. If those links are hard coded in your posts, you may need to update them in your database.

    I would do a search and replace of the links in the wp_post.
    Lorelle wrote a good post about this here - http://lorelle.wordpress.com/2005/12/01/search-and-replace-in-wordpress-mysql-database/

  3. One more thing @imikedesigns, I'm not sure that the .html extension works on pages.
    You might need a plugin like this one - http://wordpress.org/extend/plugins/html-on-pages/

    But it's very old. I would reconsider adding the .html personally.
    I'm not sure there's any benefit.

  4. Michael Moore
    Posted 3 years ago #

    Thanks for the reply. But I can't think of a way to search and replace them because they are all different links. It would bascially be a manual update of 1200 links at that point. Im hoping this can be done with .htaccess or or an add_rewrite_rule. Im just unsure of the regex to use.

  5. Michael Moore
    Posted 3 years ago #

    Thanks Christine. Reading your post, I realized youre right. There is no reason to use .html. But, I still had .html hardcoded links as well. So, I removed .html from my permalink structure added

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

    to my .htaccess to redirect those hardcoded .html links to /category/postname structure links. Works great.

Topic Closed

This topic has been closed to new replies.

About this Topic