Regex - how to combine everything except a specific template

I am using Apache and I want to redirect all received requests to the ssl virtual host.

So, I have the following line in a regular http virtual host:

RedirectMatch (. *) Https://www.mydomain.com $ 1

which usually replace everything with $ 1.

It works great. But now I need to access a specific CGI that cannot be on the SSL virtual host. Therefore, I would like to redirect all requests except the following:

" http://www.mydomain.com/mycgi/cgi.php "

I have a search on this forum and you found a message about excluding regular expressions, but no one is working. Any help would be greatly appreciated.

Thank. Alain

+5
source share
2 answers

Apache 2.2 and later have negative regex support. If you are using Apache 2.2 or later, this should work:

RedirectMatch ^/(?!mycgi/cgi.php)(.*) https://www.mydomain.com/$1
+2
source

I believe RedirectMatch is a short sorting scheme . This means that if you add another RedirectMatch before your match, only the first match will be executed. so something like ...

RedirectMatch (/mycgi/cgi.php) http://www.mydomain.com$1 
RedirectMatch (.*) https://www.mydomain.com$1 
+1
source

All Articles