Redirect all except one directory in Apache

Print

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 (.*) https://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 (.*) https://www.mydomain.com/$1 [R=301,L]
Web Servers
Comments (1)
Thanks
1 Monday, 09 December 2019 11:07
Paul
MAN!!!!!!!!
I ran around all internet trying to find this. Any code i found worked for me.
Ty so much for your time to do so!
yours worked completaly fine.!!
yvComment v.1.24.0