WordPress.org

Ready to get started?Download WordPress

Forums

Redirecting Old Permalinks to New Ones (4 posts)

  1. bgswm1
    Member
    Posted 8 years ago #

    I am looking for a way to redirect my old permalinks to the new ones. I am currently using the http://www.example.com/entry/post_id structure and am looking to change to http://www.example.com/entry/post_name for SEO purposes.

    I am fine with editing the code in the .htaccess file but would appreciate someone helping me out with that since I don't really understand it that well. I'm obviously looking for a solution that will automatically do this for all posts rather than doing this for each individual post. We have well over 2000 posts and that would be virtually impossible.

    I have not found any past forum topics about this exact issue but if you find one, please send along the link.

    Thanks,

    Doug

  2. bgswm1
    Member
    Posted 8 years ago #

    anyone know of a plugin to change these permalinks without loosing all of my posts that have already been indexed?

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    You're fortunate in that your "old" structure uses the post id. Because of this, some clever rewriting can get you more or less what you want.

    One lesser known fact is that even when you're using "pretty" permalinks, you can still access individual posts by this method:
    http://example.com/?p=post_id

    So, in your case, this link:
    http://www.gadgetell.com/entry/2737
    is equivalent to this link:
    http://www.gadgetell.com/?p=2737

    Both go to the same entry.

    So if you want to do some rewriting via htaccess to convert the first one to the second one, you can. You'll need to recognize the /entry/(numbers only) and rewrite accordingly.

    Might google "mod_rewrite" and try to figure out the syntax and such. It's not particularly easy.

  4. davidchait
    Member
    Posted 8 years ago #

    I'm doing something similar... And found I needed to hand code a solution in my case.

    htaccess isn't the solution, as you need to rewrite to the proper permalink. it needs to be done in code, I'm doing my work a bit 'late' in header.php at the moment, but might try moving it into a plugin so I can handle things right after plugins are done (and before the query actually executes).

    also, you may find you want to change from:
    example.com/entry/[postID]
    to a different 'string' for identifying easily the new format:
    example.com/posts/[post-slug]

    At that point, you want to check to see if the incoming url/request uses the old format, and if so grab the post from the db, have wp build a permalink for it (which, since you have changed formats is easy), and send back a permanent redirect to the new format permalink.

    If I find that I have a somewhat generalized-solution I can make into a plugin, I'll let folks know. There IS a plugin out there that does redirects to the canonical form of a given permalink (so, lacking slash gets redirected to terminating slash, etc.), and that might give you a basis for making a plugin for yourself that has most of the heavy lifting done already. Worth a looksee.

    -d

Topic Closed

This topic has been closed to new replies.

About this Topic