I need to do a 301 directory redirect in my httpd.conf file but exclude a subdirectory within the directory.

Example: RedirectPermanent /redirect/ http://www.mysite.com/.

But I want to exclude this subdirectory /redirect/example/.

Any ideas?

I tried this and it didn't work:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/redirect/example/?$ [NC] 
RewriteRule ^/redirect/? mysite.com [R=301,L] 
  • Have you tried anything yet? If so, please post it in your question.
    – John Conde
    Sep 12, 2013 at 13:08
  • I do not think you can do such exclusion with RedirectPermenent directive -- you need to use more powerful mod_rewrite where you can create much more powerful rules (compared to simple rules available for RedirectPermanent).
    – LazyOne
    Sep 12, 2013 at 14:30
  • I tried this --- didnt work.
    – OKSJohnson
    Sep 12, 2013 at 15:16
  • RewriteEngine On RewriteCond %{REQUEST_URI} !^/redirect/example/?$ [NC] RewriteRule ^/redirect/? mysite.com [R=301,L]
    – OKSJohnson
    Sep 12, 2013 at 15:17
  • 1) Have you restarted Apache after such changes? It is required to re-read httpd.conf file -- any changes there are not get picked up automatically (compared to .htaccess) 2) just FYI: this will redirect all in redirect folder except /redirect/example (I mean, /redirect.example/1.html will not be redirected) 3) Since you have access to httpd.conf, you can enable rewrite logging (on max level) and see why that particular request is failing
    – LazyOne
    Sep 12, 2013 at 16:00

1 Answer 1


You should be able to do a RedirectPermanent for the parent directory then setup a sym link to the example directory in your web root dir.

Now test that this much actually works. If it does, create an Alias (http.conf) for the old directory to now point to the new directory link.

Assuming that RedirectPermanent is just looking for URLs which begin with specific text this should work. Unfortunately, I haven't tested any of this but presume that it'd work.

  • After working on this off and on for a couple of days, I finally came up with a combination that works:
    – OKSJohnson
    Sep 18, 2013 at 12:01
  • 1
    RewriteEngine on RewriteCond %{REQUEST_URI} !^/redirect/example/.*? [NC] RewriteRule ^/redirect/? mysite.com [R=301,L]
    – OKSJohnson
    Sep 18, 2013 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.