I have just produced a brand new website and am prepared to switch from an my current webserver to a different webserver.

The present webserver is going to be re-named www2 The brand new webserver is going to be referred to as world wide web

I wish to redirect all traffic from www2 to www except for just one directory. My directory structure appears like this:


I must redirect everything towards the equivalent www page

 e.g. www2.mydomain.com/orange/index.html -> www.mydomain.com/orange/index.html
 www2.mydomain.com/turquoise/index.html -> www.mydomain.com/turquoise/index.html

EXCEPT for that /archive folder. I'd like customers asking for :

www2.mydomain.com/archive/important-page1.html to see the page on www2 and not be rerouted.

Will I use mod_rewrite or mod_redirect? And may I set this up in httpd.conf?


Yes, you'd need mod_rewrite. Try:

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

Note: The 301 in R=301 is really a permanent redirect, you will need to change it out to 302 if you would like so that it is temporary.

Inside the VirtualHost config in httpd.conf (or httpd.conf.d file) for www2.mydomain.com add:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/archive.*
RewriteRule ^(.*)$ http://www.mydomain.com$1