I am trying to write a mod_rewrite rule for my apache server. My requirement is that I have three web applications on a server, out of which all request to HTTP scheme should be redirected to HTTPS.
Here's what I have written :
RewriteEngine On
RewriteCond $1 ^abc$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
This doesn't seems to be working fine. I am trying to run application with abc
context root to run on HTTP and all other requests to be redirected to HTTPS URL.
Can anyone tell me what am I doing wrong.
I see a couple of problems with your first rule:
/abc
, not abc
.I suggest getting rid of the first rule, and adding the /abc exclusion to the second rule:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/abc$ [NC]
RewriteRule $ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
If you also want to force /abc to be on HTTP and not HTTPS, then you could add a second rule:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/abc$ [NC]
RewriteRule $ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]