Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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] 
share|improve this question
    
Have you tried anything yet? If so, please post it in your question. –  John Conde Sep 12 '13 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 '13 at 14:30
    
I tried this --- didnt work. –  OKSJohnson Sep 12 '13 at 15:16
    
RewriteEngine On RewriteCond %{REQUEST_URI} !^/redirect/example/?$ [NC] RewriteRule ^/redirect/? mysite.com [R=301,L] –  OKSJohnson Sep 12 '13 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 '13 at 16:00
add comment

1 Answer

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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