I would like to redirect as such...
http://old.com/a/b/ -> http://new.com/y/z/
http://old.com/a/b/file.php -> http://new.com/y/z/
http://old.com/a/b/c/file.php -> http://new.com/y/z/
http://old.com/a/b/anything -> http://new.com/y/z/
http://old.com/a/b/EXCLUDE.php -> http://old.com/a/b/EXCLUDE.php
I currently have the following in httpd.conf and it redirects correctly:
RedirectMatch 301 /a/b/(.*) http://new.com/y/z/
I don't know how to exclude one file from being redirected.
Basically I want all URL's starting with "old.com/a/b/" to go to a singe new URL, except I want a single URL to be ignored.
Using a negative lookahead in the regular expression should work:
RedirectMatch 301 /a/b/(?!EXCLUDE.php) http://new.com/y/z/
If you want the rest of the path to carry over with the redirect, use the backreference $1 as in:
RedirectMatch 301 /a/b/(?!EXCLUDE.php) http://new.com/y/z/$1
I know it's been answered but for people who want some RewriteRule stuff:
http://old.com/a/b/ -> http://new.com/y/z/
http://old.com/a/b/file.php -> http://new.com/y/z/
http://old.com/a/b/c/file.php -> http://new.com/y/z/
http://old.com/a/b/anything -> http://new.com/y/z/
http://old.com/a/b/EXCLUDE.php -> http://old.com/a/b/EXCLUDE.php
This should work:
RewriteCond %{HTTP_HOST} ^old\.com [NC]
RewriteCond %{REQUEST_URI} !^(/a/b/EXCLUDE\.php) [NC]
RewriteRule /a/b/(.*) http://new.com/y/z$1 [QSA,NC,R=301]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With