htaccess Question

Discussion in 'General Programming Chat' started by blacktrilby, Jun 24, 2011.

  1. blacktrilby

    blacktrilby Power Member

    Joined:
    Dec 9, 2008
    Messages:
    545
    Likes Received:
    417
    Occupation:
    Webmaster
    Location:
    Matt Cutts Underwear
    I want to move a site from joomla to wordpress.
    All the current urls have underscores in them

    Is the a way to do a permanent redirect for all urls
    eg. mysite.com/this_is_a_page

    to
    mysite.com/this-is-a-page

    or would I have to redirect all pages seperately?
    Thanks
    BT
     
  2. nickvincente

    nickvincente Junior Member Premium Member

    Joined:
    Mar 30, 2011
    Messages:
    178
    Likes Received:
    19
    Occupation:
    Webmaster/SEO
    Location:
    Europe
    sure, If you need to change the URL of a page as it is shown in search engine results, we recommended that you use a server-side 301 redirect. This is the best way to ensure that users and search engines are directed to the correct page. The 301 status code means that a page has permanently moved to a new location.
    read more at http://www.google.com/support/webmasters/bin/answer.py?answer=93633
     
  3. blacktrilby

    blacktrilby Power Member

    Joined:
    Dec 9, 2008
    Messages:
    545
    Likes Received:
    417
    Occupation:
    Webmaster
    Location:
    Matt Cutts Underwear
    Thanks but what I want to know is, is there a way to do it just using one rule or will I have to do it for every url?
     
  4. other_henry

    other_henry Junior Member

    Joined:
    Jun 1, 2011
    Messages:
    107
    Likes Received:
    19
    Occupation:
    Freelance coder, server guy
    Location:
    US

    You need to use this code and repeat it for the max number of _ possible, add another pattern & replacement.

    assuming php pages:

    Code:
    rewriteRule ^([^_]*)_([^_]*)\.php$ mysite.com/$1-$2.php [R=301,L]
    rewriteRule ^([^_]*)_([^_]*)_([^_]*)\.php$ mysite.com/$1-$2-$3.php [R=301,L]
    etc....
    
    (I can't post the URLs correctly, add http in front of the domain)
     
    • Thanks Thanks x 1
    Last edited: Jun 25, 2011
  5. blacktrilby

    blacktrilby Power Member

    Joined:
    Dec 9, 2008
    Messages:
    545
    Likes Received:
    417
    Occupation:
    Webmaster
    Location:
    Matt Cutts Underwear
    Thank you so much. I will give it a go :)