Redirect HTTP to HTTPS Using .htaccess

Untitled

.htaccess file is used to the configure of file directory, URL redirection, access control. .htaccess file hidden in the control panel of the UNIX operating server.

Redirect HTTP to HTTPS Using .htaccess Example code

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect to www domain if not already
RewriteCond %{HTTPS_HOST} ^yourdomain [NC]
RewriteRule (.*) https://www.yourdomain/$1 [R=301,L]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain/$1 [R,L]

# Handle Front Controller…
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* – [E=HTTPS_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Leave a Reply

Your email address will not be published. Required fields are marked *