Related Items  

Linux and Windows Support  

make-it-great-again

Login or Register  

If you wish to contribute an article, please login or register.

Redirect all except one directory in Apache

PrintE-mail

Q. I would like to redirect all but one directory in Apache. How do I do that?

A. The process is very simple, using mod_rewrite:

Let's say that "directory1" is what you would like to continue using and everything else is to be redirected:

RewriteCond $1 !^directory1
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

You can add as many RewriteCond as needed (so it can be more than just one directory). 

RewriteEngine on RewriteCond $1 !^archive RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]

Add your comment

Your name:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:
yvComment v.1.24.0
   
Copyright © 1999 - 2017 Virtual Helpme | t | Original Template: Allrounder