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

Redirect All But One Directory

Discussion in 'Server Configuration and Hosting' started by yavuz, Oct 24, 2013.

  1. yavuz

    yavuz Well-Known Member

    I'm trying to redirect a domain to another using .htaccess but there is one directoy inside the domain that I don't want to redirect:

    ## list conditions for redirecitons: by equality or inequality, as needed
    RewriteCond %{http_host} !^www.targetsite.net$ [nc]
    ## a few folders not to be redirected
    RewriteCond %{THE_REQUEST} !^.*\/(upload|baddirectory2|baddirectory3)\/*\ HTTP/
    ## a few pages not to be redirected
    RewriteCond %{THE_REQUEST} !^.*\/blah\.html\ HTTP/
    RewriteCond %{THE_REQUEST} !^.*\/some-path\/blahbla\.html\ HTTP/
    ### and so on, whatever conditions
    RewriteRule ^(.*)$ http://www.targetsite.com/$1 [r=301,nc,L] 
    The redirection works but all including the directory I don't want to redirect changes too.
  2. yavuz

    yavuz Well-Known Member

    I've used cPanel's redirection instead. Better, less painful solution.

Share This Page