Redirecting all urls in directory to new one

Discussion in 'Apache' started by popoman, Mar 12, 2007.

  1. #1
    How can I redirect any possible url under domain.com/olddir/ including the dir itself all to go just to domain.com/newdir/ using a 301 redirect in .htaccess?

    I mean something like:

    redirect 301 /olddir/ http://www.domain.com/newdir/
    Code (markup):
    But that it would get every url in that old dir to go to the exact new link...

    Thanks!
     
    popoman, Mar 12, 2007 IP
  2. Cachi

    Cachi Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I recall doing something like that before and removing the last / solved it
     
    Cachi, Mar 13, 2007 IP
  3. malmklang

    malmklang Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi!

    EDIT
    RedirectMatch seemed to be my friend
    RedirectMatch 301 /hp/username(/[0-9a-zA-Z]+) username.domain.tld
    Code (markup):
    Does this keep page rank?
    /EDIT

    I am sorry for bumbing this thread, but the reply from Cachi isn't doing it for me.
    If I call up the old folder and file through a browser, like domain.com/old/mayhem.php the redirect takes mayhem.php with it forming this url: domain.com/new/mayhem.php
    I want mayhem.php or any other file request to be left out, so that it only redirects to the root of the new folder.

    Now, this is just an example, in real life I can't use mod_rewrite, cause I need to redirect to a subdomain that resides outside of my public_html folder, and as I understand it, mod_rewrite can't rewrite outside of the root folder.

    Here's my code, had to remove http:// before the last username reference:
    Redirect 301 /hp/username username.domain.tld
    Code (markup):
     
    malmklang, Apr 9, 2007 IP