Force redirect to https for Nginx and Apache

A simple way to set redirect to https for any site on your nginx/apache configuration.

Apache

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]

Nginx

server {
	listen 80;
	server_name ${DOMAIN};
	return 301 https://$server_name$request_uri;
}
Show Comments