SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Chaning the URL structure of the site, is there a way to not lose the old traffic..??

    I am about to change our permalink structure of our wordpress site from:

    /%date%/%postname/

    to

    /static-folder-name/%postname%/

    Obviously this is going to suck for SEO so i was going to write an .htaccess rule to redirect our old posts to the new url structure.

    However I pretty thick with regards to .htaccess rules, so does anyone have idea of what rule i should write?

    Any help would be appreciated.

    Thanks

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    cs7,

    Is there a mapping from %date% to static-folder-name?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if that is a question directed at me?

    If so, it confused me.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    cs7,

    Yes. Is there a way to translate %date% to a specific static-file-name or is the %date% information to be merely discarded?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I didn't respond faster, not sure with the instant notification didn't get to me.

    I hate to be thick but I still not confident I understand what you are asking, maybe if I elaborate it may clarify my initial question.

    We are going to change the URL structure of a blog that already has several hundred individual articles, each with a structure of:

    /%date%/%postname/


    Now If i go in and change the permalink structure to:

    /static-folder-name/%postname%/

    I presume that it will change the URL's of all the old articles, which would make us lose a bunch of traffic and generally be poor for SEO.

    I was under the impression that I should write a htaccess file with a rule that will redirect the old URL format to the new one, hence not rendering the old URL's useless.


    I hope that clears it up, ironically i think I am more confused than at the beginning.

    thanks again for any help.

    -w

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    cs,

    I tend to do that to people

    Okay, since the new blog does NOT need the information contained in the %date% of the original link and the new static-folder-name is whatever you want it to be
    Code:
    # .htaccess in DocumentRoot
    RewriteEngine on
    RewriteRule ^/?\d{4}-\d{2}-\d{2}/([-a-zA-z0-9_]+)$ /static-folder-name/$1/ [L]
    where:

    ^/? is the start anchor where /? accounts for the difference between A1 & A2
    \d{4}-\d{2}-\d{2} is the assumed data format, i.e., 2007-10-23
    \d is the same as [0-9], just a regex abbreviation for digit
    (if you remove the start anchor, . would work just as well)
    ([-a-zA-z0-9_]+) is the assumed format of the %postname% field
    $ is the end anchor - to be sure we "got it all"

    Note that SPECIFICITY would have prevented making an @$$ out of u and me on all those formats!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    ****, I was not expecting anything like that.

    Hahahah.

    Thank god for you.

    I really appreciate it, mucho help.

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    cs,

    What didn't you expect, that I speak in technobabble?


    The rest of your post made it seem as if you understood what I said - but feel free to ask if there are any questions. The person you may help might be yourself - and anyone else who wonders through your thread.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe.

    Ok so I thought that i would be able to work it out on my own but no.

    So here is the exact format of the current URL's

    /%year%/%monthnum%/%day%/%postname%/

    and we want to change them to:

    /static-name/%postname%/


    Based on your rule, I modified it slightly to fit the date folders, so my htaccess file read like

    ewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]
    RewriteRule ^/\?d{4}\/d{2}\/d{2}/([-a-zA-z0-9_]+)$ /mens-buying-guide/$1/ [L]
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress



    But I guess my logic didn't work, as when I went to an a post using the old format,

    http://www.domain.com/2007/10/23/clock-blocks/

    it didn't redirect me to

    http://www.domain.com/static-folder/clock-blocks/


    Sorry, if I am being slow here.

  10. #10
    SitePoint Enthusiast bdude's Avatar
    Join Date
    Jan 2006
    Location
    In a house.
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this plugin might help you
    SUPPORT FOR NEW BLOGGERS - TRY THE Blogging Forum

  11. #11
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I appreciate it, but I tend to agree with this article.

    http://www.alistercameron.com/2007/0...-shouldnt-use/

  12. #12
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    cs,

    First, I agree that nothing more than good mod_rewrite code is required (or necessary).
    Quote Originally Posted by cyrillsneer7 View Post
    {snip}

    So here is the exact format of the current URL's

    /&#37;year%/%monthnum%/%day%/%postname%/

    and we want to change them to:

    /static-name/%postname%/
    Well, I haven't taught you to specify in terms of regex yet, have I? Is %year% like 2007 (\d{4}) or pig (like Chinese year of the pig)? At least you 'specified' that %monthnum% is a number but is it single or double digit? Ditto %day%? You COULD get carried away and specify %year% like ([12][90]{2}[0-9]) to specify any year from 1990 through 2009 but that's getting carried away. For me, unless you want to rely on mod_rewrite to do 'ALL' your error checking for you, \d{4} seems sufficient to specify four digits.

    Then, if you're going to use these dates to access the db, it really should be in the format suggested several posts ago (yyyy-mm-dd).

    On the other hand, you're apparently not using the date at all so it really doesn't matter, does it?
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    # RewriteRule ^/\?d{4}\/d{2}\/d{2}/([-a-zA-z0-9_]+)$ 
    # misplaced ? ruined that code!
    RewriteRule ^/?\d{4}\/d{2}\/d{2}/([-a-zA-z0-9_]+)$ /mens-buying-guide/$1/ [L]
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    # You don't know whether you have mod_rewrite enabled???
    # If you don't, the mod_rewrite code above would have caused
    # ... a 500 error already!
    RewriteEngine On
    # Again?
    RewriteBase /
    # WRONG!
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /index.php [L]
    </IfModule>
    
    # END WordPress
    WordPress writes crappy (generic) mod_rewrite code.

    Okay, I think that your biggest error was the misplaced ? in YOUR mod_rewrite code. However, consider getting rid of all the GARBAGE and the date code (which doesn't matter), too! Don't forget to add in the blue.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  13. #13
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much, I really appreciate your help, talk about going out of your way.

    RewriteEngine On
    RewriteCond &#37;{HTTP_HOST} !^www.domain.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    RewriteRule /([-a-zA-z0-9_]+)$ /mens-buying-guide/$1/ [L]
    # BEGIN WordPress
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /index.php [L]
    # END WordPress

    Is now working perfectly, this has been a pain for a week now and six other people including myself say thank you.

  14. #14
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    cs,

    It's party time!

    BTW, I'd also get rid of the / in RewriteRule .? /index.php [L]

    Now, did you learn anything from that (except that you really do need to understand mod_rewrite in order to use it)? If so, please summarize so (1) I can learn how to help members better (faster) and (2) to help others learn, too.

    BTW, you're ALL welcome!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  15. #15
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I realised that I know nothing about mod_rewrite and the only way I could possible hope to write my own .htaccess file would be to sit down for sometime and read the different syntaxes properly.

    I learnt that by using r=301, I can tell the search engines I have permanently moved the URL.

    I learnt if I remove some the information that wordpress automatically writes, my server gets a internal 500 error.

    I learnt that Top Gun is the most homo-erotic movie ever made, and to wax on and wax off.


  16. #16
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    cs,

    Good response - I deserved that!

    Oh, well, mod_rewrite is just the application of logic (rational thinking) and translating that into code with regex using very simple rules.

    R=301 is good (you've got it!).

    500 says that you changed the code to something illegal (did it wrong) so that's more a semantic problem than a WordPress problem (although their mod_rewrite code IS a problem).

    Top Gun - you actually liked that? Okay, as a pilot, I have to say that the music was great but the flying scenes were crap - too unrealistic to be shown to the general public (knowing what is REALLY going on ruins too many films for me).

    Enjoy!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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