WordPress.org

Ideas

Maintain History of Broken Permalinks and Redirect

  1. Mike Schinkel
    Member

    If I change my permalink structure or category base it breaks almost all my links. I'd like to see a feature added that would record the old URL and the new URL, and whenever someone visits the old URL redirect it with a HTTP code 301 "Moved Permanently" to the new URL. For example, assume I went from:

    /%postname%/

    to

    /%year%/%postname%/

    And to illustrate assume I had only one post with a slug of "foo-bar" published in 2007. The redirect table would contact two fields:

    old_url_path -> new_url_path
    /foo-bar/ -> /2007/foo-bar/

    If for some reason the old URL had been replaced by a new URL, i.e. we went from this:

    Old Post URLs: /%postname%/
    Old Archive URLs: /archives/

    to this:

    New Post URLs: /%year%/%postname%/
    New Archive URLs: /categories/

    Now let's assume we had previously written a post with the slug "categories" in 2006, admittedly a contrived example. We'd record the following in the redirect table:

    old_url_path -> new_url_path
    /categories/ -> /2006/categories/

    However, because the URL path /categories/ now is mapped to the archives it will takes priority on any request. So for those wanting the post previously referenced by old resource on the page returned by the URL path /categories/, it could include a link at that top that says:

    "There was previously a post with this same
    URL with the title "Categories" which is now
    located at /2006/categories/. Were you
    looking for that instead?"

    If the user answered YES it could also record the referer and then notify the admin to configure to automatically redirect whenever that referer was found in the HTTP headers.

    An admin could optionally turn this off the notice at the top of the page, if desired, and also it should optionally not appear if redirected from an existing page on the site were an index would exist.

    Lastly, there should be an interface that would allow the admin to delete any redirects, add any of their own, and also tag any to not show up with a message at the top of a page when the URL was superceded.

    BTW, I'd LOVE to write a plug-in for this if someone could direct me. I consider myself an advanced Windows+IIS+SQL Server+ASP developer but am just starting to learn Linux+Apache+MySQL+PHP (though I'm reading numerous books on the combined subjects of LAMP and have Ubunut installed on VMware, I've just found no books on writing WordPress plugs-ins.)

    Posted: 8 years ago #
  2. Jonathan Landrum
    Member

    12345

    Yeah, that would rock. It took me quite a while to figure out the Rewrite context required to do this feasibly. Before that, I hand-coded each redirect. The ensuing .htaccess file was 15,000+ bytes.

    Posted: 8 years ago #
  3. h3h
    Member

    12345

    Sounds great. And hard.

    Posted: 8 years ago #
  4. m0n5t3r
    Member

    12345

    Actually, there is lots of documentation; so much documentation that you'll get lost. So the best is to use the source, Luke :D

    for example: after a quick look, it seems that you could hook your modification detection to the filter option_permalink_structure and add corresponding rules to $wp_rewrite using one of the hooks in wp-includes/rewrite.php (search for apply_filters or do_action, you'll probably want either the action generate_rewrite_rules or the filter rewrite_rules_array)

    Posted: 8 years ago #
  5. Hardtana
    Member

    Doesn't this plugin do the most of it?

    http://urbangiraffe.com/plugins/redirection/

    Posted: 7 years ago #
  6. Jeff Chandler
    Volunteer Moderator and Voice of WP

    Plugins handle this pretty well

    Posted: 5 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    12345
    41 Votes
  • Status

    This is plugin territory