E-mail:vova@vbeg.ru
Skype:vova-beglecov

Redirect HTTP to HTTPS

Examples redirect all HTTP requests to HTTPS. Add the following code to the file «.htaccess».
The file is located in root folder of the website. If this file is missing then you need to create it.

Example 1 (recommended by the developers of Apache)

<IfModule mod_rewrite.c>
	Options +FollowSymLinks
	RewriteEngine On
	RewriteBase /

	# Redirect HTTP to HTTPS
	RewriteCond %{HTTPS} off
	RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>


Example 2
<IfModule mod_rewrite.c>
	Options +FollowSymLinks
	RewriteEngine On
	RewriteBase /

	# Redirect HTTP to HTTPS
	RewriteCond %{SERVER_PORT} !^443$
	RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
</IfModule>


Example 3
<IfModule mod_rewrite.c>
	Options +FollowSymLinks
	RewriteEngine On
	RewriteBase /

	# Redirect HTTP to HTTPS
	RewriteCond %{HTTPS} off
	RewriteCond %{HTTP:X-Forwarded-Proto} !https
	RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>