Reputation: 1045
I am running a simple rails application on port 3000. I have reverse proxied it to apache port 80 with mod_rewrite enabled. When I access via http and https the application works fine. Now I would like to redirect all http request to https. I already have a .htaccess file under public folder of the rails application but it doesn't seem to work.
RewriteCond %{SERVER_PORT} 80 [OR,NC]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
Domain.com points to my domain. Also I don't want my subdomains to be redirected to https. How do I achieve it?
Upvotes: 0
Views: 196
Reputation: 74018
To check if https is enabled, you can use RewriteCond
with the HTTPS
variable
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L]
Upvotes: 0
Reputation: 41209
Remove the OR condition and try:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
Upvotes: 1