Redirect everything but one file to a directory via httpd.conf / htaccess

I would like to redirect as such ... -> -> -> -> ->


Currently, httpd.conf has the following, it also redirects:

RedirectMatch 301 /a/b/(.*)


I don't know how to exclude a single file from being redirected.

Basically, I want all URLs starting with "" to navigate to the new URL, except that I want one URL to be ignored.


source to share

2 answers

Using negative form in regex should work:

RedirectMatch 301 /a/b/(?!EXCLUDE.php)


If you want the rest of the path to carry over with a redirect, use the $ 1 backreference, as in:

RedirectMatch 301 /a/b/(?!EXCLUDE.php)$1




I know this was answered, but for people looking to use the RewriteRule stuff: -> -> -> -> ->


This should work:

RewriteCond %{HTTP_HOST} ^old\.com [NC]
RewriteCond %{REQUEST_URI} !^(/a/b/EXCLUDE\.php) [NC]
RewriteRule /a/b/(.*)$1 [QSA,NC,R=301]




All Articles