Results 1 to 14 of 14

Removing dates from Wordpress URL structure... can it be done safely?

This is a discussion on Removing dates from Wordpress URL structure... can it be done safely? within the Off-Topic & Chit Chat forums, part of the Focus on Members category; The reason I am asking this here and not a WP forum? Because vBSEO staff know their stuff! So here's ...

  1. #1
    MTD
    MTD is offline
    Senior Member
    Real Name
    Mike
    Join Date
    Apr 2008
    Posts
    142
    Liked
    0 times

    Removing dates from Wordpress URL structure... can it be done safely?

    The reason I am asking this here and not a WP forum? Because vBSEO staff know their stuff!

    So here's the dilemma...

    vB is the main site and then I have WP running in domain.com/blog/. The blog part was set up about 2 years ago. Back then I made the very unwise decision of following WP's advice of using dates in the URLs, instead of just /%postname%/ by itself. So all my posts have dates in the URL.

    The problem with this is that the vast majority of posts are not time sensitive, and in fact, are often updated periodically. So let's say I have a review written from May 2009, even if it's up-to-date, it looks horrible in the SERPs seeing domain.com/blog/2009/05/post-title/. Of course, this problem will only get worse as time goes on and those dates become older and older.

    Is there any clean way using 301 re-directs to forward something like

    domain.com/blog/2009/05/post-title/

    to

    domain.com/blog/post-title/

    There's about 150 or so posts spanning 2 years. Is there a single 301 re-direct formula that would cover all of them? Or would an individual rule have to be created for each month and year (i.e. /2009/05/).

    Some of my posts rank extremely high and have a good number of backlinks, so I don't want to lose those.

  2. #2
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,789
    Liked
    657 times
    Blog Entries
    2
    try:

    Code:
    RewriteRule blog/[0-9]+/[0-9]+/(.*) http://www.domain.com/blog/$1 [L,R=301]

  3. #3
    MTD
    MTD is offline
    Senior Member
    Real Name
    Mike
    Join Date
    Apr 2008
    Posts
    142
    Liked
    0 times
    Quote Originally Posted by Brian Cummiskey View Post
    try:

    Code:
    RewriteRule blog/[0-9]+/[0-9]+/(.*) http://www.domain.com/blog/$1 [L,R=301]
    Thanks Brian! I also came across this earlier today... will this be a problem?

    If you want to send 301 redirects from the old URLs to the new ones, then you can't really do that with an .htaccess file. The reason is that Apache's mod_rewrite doesn't have access to the title of your post, so it won't know what title to insert in the URL. You'd have to do that redirect with PHP.

    EDIT: y'know what, actually that's not entirely true. You can do some pretty crazy things with the RewriteMap directive, such as instructing Apache to ask an arbitrary program to perform the rewriting, and in that way you could have, say, a PHP script that does some database work to figure out what the title is and rewrites the URL appropriately based on that. But that seems like a way overcomplicated solution and I wouldn't suggest doing it - it'll be much cleaner and easier to just send the redirect directly from PHP.
    (from http://stackoverflow.com/questions/6...irects-with-mo)

  4. #4
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,789
    Liked
    657 times
    Blog Entries
    2
    Since you already have the title in your source url, looking up the title is a non-issue. That would only apply if you were moving from something like
    blog/date/postid/ to blog/title/

  5. #5
    MTD
    MTD is offline
    Senior Member
    Real Name
    Mike
    Join Date
    Apr 2008
    Posts
    142
    Liked
    0 times
    Great!

    So here is the current .htaccess file in /blog/

    Code:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    
    # END WordPress
    Where should I put this...

    Code:
    RewriteRule blog/[0-9]+/[0-9]+/(.*) http://www.domain.com/blog/$1 [L,R=301]
    ...and will this re-direct inbound links to both www and non-www versions?

    Thanks!

  6. #6
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,789
    Liked
    657 times
    Blog Entries
    2
    RewriteBase /blog/
    HERE
    RewriteCond %{REQUEST_FILENAME} !-f

    and yes, this should match both versions. if you have a non or www-rule ahead of it, it will get directed on that first, then hit this rule.

  7. #7
    MTD
    MTD is offline
    Senior Member
    Real Name
    Mike
    Join Date
    Apr 2008
    Posts
    142
    Liked
    0 times
    I made the change tonight but unfortunately the above was giving 404 errors. After much Googling and trial and error, this is what I came to:

    Code:
    RedirectMatch permanent /blog/[0-9]{4}/[0-9]{2}/([a-z0-9\-/]+)/ http://domain.com/blog/$1
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>
    
    # END WordPress
    Have tested quite a bit and seems to be working good. Is this okay?

    The only problem I'm having is with 3 posts (out of 200ish) that are not redirecting. What do those 3 have in common? This "-–-" (short hash, long hash, short hash). So these 3 posts have titles like "sample-–-word-word-word" and that -–- is what's not redirecting.

    When I copy/paste the middle long hash into the htaccess (via notepage++) it shows up as a short hash instead. Apparently the long hash is not a valid character in basic text so I can't use it to make new rules for those posts. Any ideas how I can solve this?

  8. #8
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,789
    Liked
    657 times
    Blog Entries
    2
    ([a-z0-9\-/]+) only lets in letters, numbers, and the -. You can wild card this to (.*) which will match everything.

  9. #9
    MTD
    MTD is offline
    Senior Member
    Real Name
    Mike
    Join Date
    Apr 2008
    Posts
    142
    Liked
    0 times
    The (.*) worked perfectly, thanks Brian!

  10. #10
    Member
    Real Name
    Nick
    Join Date
    Mar 2009
    Posts
    46
    Liked
    0 times
    Hi
    Im trying to do a similar thing on my wordpress site but not sure how its done. The main wordpress is in the top directory and not /blog or anything like that. Trying to get http://dev.anfieldindex.com/2011/03/...future-is-red/ to look like Part one of look at the Liverpool FC U18's on Anfield Index Anfield Index – analysis of LFC players and matches using Opta stats which I have done ok in the settings but need to get any old articles redirecting so they go to the new place. The site is pretty new so I doubt many people have it bookmarked but I have tweeted a lot of links so that is where people will get the error from unless I fix it.

    Any Ideas? Thanks

  11. #11
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,789
    Liked
    657 times
    Blog Entries
    2
    Try the same rule...

    Code:
    RedirectMatch permanent /[0-9]{4}/[0-9]{2}/((.*)+)/ http://domain.com/$1

  12. #12
    Member
    Real Name
    Nick
    Join Date
    Mar 2009
    Posts
    46
    Liked
    0 times
    Cheers brian.

  13. #13
    Member
    Real Name
    Nick
    Join Date
    Mar 2009
    Posts
    46
    Liked
    0 times
    Hi

    Got this working thanks. But one problem has come up since I changed it. Only on one section of the site though which is strange!

    On Anfield Index – analysis of LFC players and matches using Opta stats if you click on read blog on a username with a space with it such as Ashley langley it comes up with a not found error. Instead of adding a - between the names, it puts a %20 there. So if I manually change the url from http://www.anfieldindex.com/author/Ash%20Langley to Ash Langley « Anfield Index – analysis of LFC players and matches using Opta stats in the browser bar it works fine.

    Anywhere else on the site it puts in the correct - but only in that member blogs part. Any idea what this would be? No one has changed the htaccess file. I know this isnt a vb issue but no one at wp seems to know as much as anyone here.

    Thanks

  14. #14
    vBSEO Staff Brian Cummiskey's Avatar
    Real Name
    Brian Cummiskey
    Join Date
    Jul 2009
    Location
    btwn NYC and Boston
    Posts
    12,789
    Liked
    657 times
    Blog Entries
    2
    You will need to consult with word press about their re-write structures.

Similar Threads

  1. Removing boards from URL structure?
    By I, Brian in forum Custom Rewrite Rules
    Replies: 8
    Last Post: 06-29-2007, 04:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •