Redirect without losing the baclinks

Discussion in 'Apache' started by tnk, Oct 25, 2007.

  1. #1
    Hi

    I have a website, which is operating under a folder . So the front page url is

    domain.com/sub-folder

    I have lot of backlinks but i do want to remove the "sub-folder" and put everything back in parent directory

    However I want my backlinks to still work. If someone have a backlink

    domain.com/sub-folder/page.html it should redirect it to domain.com/page.html since after I put everything in parent, the subfolder will not exist

    Can this be done ?
    Please help
     
    tnk, Oct 25, 2007 IP
  2. inworx

    inworx Peon

    Messages:
    4,860
    Likes Received:
    201
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to post it in apache section as this needs .htaccess settings.
     
    inworx, Oct 26, 2007 IP
  3. tnk

    tnk Active Member

    Messages:
    277
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    68
    #3
    Thanks ... i dont know how to do that. So not sure how i could have figured that out.

    But will remember for next time.
     
    tnk, Oct 26, 2007 IP
  4. mergemedia

    mergemedia Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    put an .htaccess file in the documentroot which contains:

    
    RewriteEngine On
    RedirectPermanent /sub-folder/page.html http://yourdomain.com/
    
    Code (markup):
     
    mergemedia, Oct 26, 2007 IP
  5. tnk

    tnk Active Member

    Messages:
    277
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    68
    #5
    Thanks mergemedia

    But i am not sure if this will take care of all pages. I have hundreds of URLs . So How will we modify this to make it work for all pages

    /sub-folder/page1.htm - page1.htm

    /sub-folder/page2.htm goes to page2.htme
     
    tnk, Oct 26, 2007 IP
  6. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Bring on the power of regular expressions !

    RewriteRule /sub-folder/(.*) /$1 [R=301,NC,L]
    Code (markup):
    The $1 in the second part of the rewrite rule matches anything in the parentheses () in the first part of the rewrite rule.

    So if you request
    /sub-folder/foo.html
    Code (markup):
    you will be told that the page has moved permanently to
    /foo.html
    Code (markup):
    If you request
    /sub-folder/anotherfolder/yetanotherfolder/foo.html
    Code (markup):
    you will be told that the page has moved permanently to
    /anotherfolder/yetanotherfolder/foo.html
    Code (markup):
     
    Ladadadada, Oct 27, 2007 IP