Set apache redirect from http to https for specific url
I would like to redirect any url that has / test to https: // localhost / test . Also, if the url / test? User = 123, it should be redirected to https: // localhost / test? User = 123 or most likely if url is / test / test_db / user? id = 123 & pwd = 123 need to redirect to https: // localhost / test / user / test_db / user? id = 123 & pwd = 123
All other requests should be redirected to the html page that says "Access Denied" in the root folder (http: //localhost/accessdenied.html).
How to achieve this with RedirectMatch in apache. I tried something like
RedirectMatch permanent ^test/(.*)$ https://localhost/test/$1
Which didn't work.
source to share
I wonder if this is better as a ServerFault question.
Anyway:
I don't know how you can achieve this with RedirectMatch, but I know how you can do it with ModRewrite:
RewriteEngine On$
RewriteCond %{HTTPS} off$
RewriteRule ^/bla https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]$
This is a pretty generic form that will work for any HTTP host (since I don't know any details about your host) and redirects anything that matches bla
at the beginning of the url and isn't already Https, with arguments and that's it.
source to share