I would like to redirect any URL path that is having a /test to https://localhost/test. Also, if an url is /test?user=123 it has to be redirected to https://localhost/test?user=123 or rather if the url is /test/test_db/user?id=123&pwd=123 has to be redirected to https://localhost/test/user/test_db/user?id=123&pwd=123
All other requests of any kind has to be redirected to a html page that says "Access denied" in the root folder(http://localhost/accessdenied.html).
How do I achieve this with RedirectMatch in apache. I tried something like
RedirectMatch permanent ^test/(.*)$ https://localhost/test/$1
Which did not work.
I wonder if this is better as a ServerFault question.
Anyway:
I don't know how you can achieve this with RedirectMatch, but I do know how you can do this with ModRewrite:
RewriteEngine On$
RewriteCond %{HTTPS} off$
RewriteRule ^/bla https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]$
This is a fairly generic form that'll work for any HTTP Host (as I don't know any details about your host) and will redirect anything that matches with bla at the start of the URL and isn't already Https, with arguments and everything.
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