1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HTAccess 301 Redirects - Need Help!

Discussion in 'General Programming Chat' started by -Jericho-, Sep 14, 2011.

  1. -Jericho-

    -Jericho- Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jan 10, 2010
    Messages:
    2,849
    Likes Received:
    1,704
    Location:
    Stalking My Ex-Wife
    I'm stuck. I don't know much about htaccess and I'm just winging it. Can someone look at the code and tell me what's wrong with it. I simply want to redirect an old site to a new site and the only changes are the domain, a variable that will match between old/new pages and an added word to the permalink structure.

    Here's one of the variations I've tried so far:
    Code:
    Options +FolowSymlinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC]
    RewriteRule ^(.*)$ http://www.newdomain.com/matchingword1-$1-matchingword2-differentword-matchingword3/ [R=301,L]
    The section (.*) will be the exact same as $1 on the new domain but the permalink is a little different. The part of the permalink that is (.*) will be anything from multiple words and numbers.

    For example: matchingword1-this-page-is-1st-matchingword2-matchingword3/ redirects to newdomain dot com/matchingword1-this-page-is-1st-matchingword2-differentword-matchingword3/
     
    Last edited: Sep 14, 2011
  2. mrdexter

    mrdexter Junior Member

    Joined:
    May 20, 2011
    Messages:
    184
    Likes Received:
    63
    Are you creating a list of rules or wanting to create one conditional rule?

    If you are happy to have a list of rules you can create the new URLs in excel using a find and replace, then use
    Code:
    http://seo-website-designer.com/HtAccess-301-Redirect-Generator
    to create the file.

    If you have gazillions of pages and want to create a conditional rule then I think you might need to use

    Code:
    RewriteCond %{REQUEST_URI}
    instead of

    Code:
    RewriteCond %{HTTP_HOST}
     
  3. -Jericho-

    -Jericho- Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jan 10, 2010
    Messages:
    2,849
    Likes Received:
    1,704
    Location:
    Stalking My Ex-Wife
    I have around 12,000 pages to redirect. So doing them one by one is a pain and the site has been taken down for sometime. I'm simply trying to recapture the backlinks from it.

    The request uri didn't work either.
     
  4. mrdexter

    mrdexter Junior Member

    Joined:
    May 20, 2011
    Messages:
    184
    Likes Received:
    63
    It's not because you're using $ instead of % is it?

    (I always get confused - this might just be for {query_string}...)

    Code:
    Options +FolowSymlinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC]
    RewriteRule ^(.*)$ http://www.newdomain.com/matchingword1-[B]%1[/B]-matchingword2-differentword-matchingword3/ [R=301,L]
     
  5. -Jericho-

    -Jericho- Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jan 10, 2010
    Messages:
    2,849
    Likes Received:
    1,704
    Location:
    Stalking My Ex-Wife
    No that doesn't work either.

     
  6. mrdexter

    mrdexter Junior Member

    Joined:
    May 20, 2011
    Messages:
    184
    Likes Received:
    63
    Ok I think you do need a query string, I'm just not sure of the syntax.

    Something like

    Code:
    RewriteCond %{QUERY_STRING}  ^$
    RewriteRule ^domain\.com/matchingword1-(.*)-matchingword2-matchingword3/$ http://www.newdomain.com/matchingword1-\$1-matchingword2-differentword-matchingword3/\ [R=301? [R=301,NE,NC]
    
     
  7. -Jericho-

    -Jericho- Jr. Executive VIP Jr. VIP Premium Member

    Joined:
    Jan 10, 2010
    Messages:
    2,849
    Likes Received:
    1,704
    Location:
    Stalking My Ex-Wife
    Nope didn't work either. Thanks for trying.
     
  8. mrdexter

    mrdexter Junior Member

    Joined:
    May 20, 2011
    Messages:
    184
    Likes Received:
    63
    Sorry - all out of ideas :(
     
  9. xenon2010

    xenon2010 Regular Member

    Joined:
    Apr 27, 2010
    Messages:
    231
    Likes Received:
    48
    Occupation:
    web and desktop apps programmer
    Location:
    prison
    Home Page:
    there you go:
    Code:
    Options +FolowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^.*domain.com/matchingword1-(.*)-matchingword2-matchingword3/ [NC] RewriteRule ^(.*)$ http://www.newdomain.com%{REQUEST_URI} [R=301,L]
    now rep me up :D