how to 301 redirect from subdirectory to new domain????

Discussion in 'Apache' started by shuman202, Jul 19, 2012.

  1. #1
    i have a problem to redirect from subdirectory to new domain??
    i do the following
    
    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^newdomain.com [nc]
    rewriterule ^(.*)$ http://www.olddomain.com/subdirectory/$1 [r=301,nc]
    
    Redirect permanent / http://www.newdomain.com/
    
    
    Code (markup):
    it redirects from
    
    http://www.olddomain.com/subdirectory
    
    Code (markup):
    to
    
    http://www.newdomain.com/subdirectory
    
    Code (markup):
    i want the redirection to the following
    
    http://www.newdomain.com
    
    Code (markup):
    i want the redirection to the home page not from a subdirectory to a subdirectory
     
    Solved! View solution.
    shuman202, Jul 19, 2012 IP
  2. #2
    The following code will probably work for you

    
    RedirectMatch 301 /subdirectory(.*) http://newdomain.com/$1
    Code (markup):
     
    RoseHosting, Jul 19, 2012 IP
    shuman202 likes this.
  3. shuman202

    shuman202 Well-Known Member

    Messages:
    638
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    145
    Digital Goods:
    1
    #3
    really thank you it works like a charm
    i did add only that code at the .htaccess
    
    RedirectMatch 301 /subdirectory(.*) http://newdomain.com/$1
    
    Code (markup):
    don't you think i should add something extra
    like that at the beging of the file...
    
    Options +FollowSymlinks
    RewriteEngine on
    
    Code (markup):
    sorry i have very little knowledge about .htaccess file configuration
     
    shuman202, Jul 19, 2012 IP
  4. shuman202

    shuman202 Well-Known Member

    Messages:
    638
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    145
    Digital Goods:
    1
    #4
    just 1 modification to your code
    you must remove the backslash from the new domain
    instead to be like that
    RedirectMatch 301 /subdirectory(.*) http://newdomain.com/$1
    Code (markup):
    to be like taht
    
    RedirectMatch 301 /subdirectory(.*) http://newdomain.com$1
    
    Code (markup):
    becasue it adds one more slash after the domain name
    anyway I'm very thankful for your help:cool:
     
    shuman202, Jul 19, 2012 IP