Need some advanced redirecting with a .htaccess rule
This is my current rule.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/content/newzealand/mpc/mpc_newzealand_website/en/home_mpc/van.*
RewriteCond %{REQUEST_URI} !^/content/newzealand/mpc/mpc_newzealand_website/en/home_mpc/truck.*
RewriteCond %{REQUEST_URI} !^/admin.*
RewriteCond %{REQUEST_URI} !^/login.*
RewriteCond %{REQUEST_URI} !^/session.*
RewriteCond %{REQUEST_URI} !^/path_maps.*
RewriteCond %{REQUEST_URI} !.*\.(gif|jpg|png|js|css|swf)
RewriteCond %{HTTP_HOST} !^www\.dealer1\.com
RewriteCond %{HTTP_HOST} !^www\.dealer2\.com
RewriteCond %{HTTP_HOST} !^www\.dealer3\.com
RewriteCond %{HTTP_HOST} !^www\.dealer4\.com
RewriteRule (.*) http://www.example.com [R=301,L]
This rule directs all traffic not in the RewriteCond to www.example.com.
However I now need the following amendment,
if this:
/content/newzealand/mpc/mpc_newzealand_website/en/home_mpc/van.*
path gets visited then I want it to redirect the www.example.com/van
The first thing that I would do is to simply this. First adding .* at the end of a pattern is redundant, and if you want to test if a URI ends with
.swfsay then you use\.swf$. Also combine rules where sensible.Next the simplest way to do a blanked exclusion is to use a “^ -“, which is just a shorthand for “always do nothing” (if the conds are satisfied). Adding an [L] means that the following rules don’t get used. Alternatively you can skip the next N rules by using [skip=N].
And specify a base, e.g. / if the
.htaccessis in DOCROOT, So:Lastly, I am really suspicious of your long URIs. The request URI everything excluding the server and query bits (e.g. for
http//server/abc/login?user=fredit is/abc/login). For example you really want to redirect everything other this path at this site to the new domain?Forcing users to use such complex URIs is a good way to discourage their visiting!