DEV Community

Fa'rath Shba 🚀
Fa'rath Shba 🚀

Posted on

Use .htaccess to redirect HTTP to HTTPs

This post is for individuals who are looking for quick fixes to redirect HTTP to HTTPS traffic.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Enter fullscreen mode Exit fullscreen mode

Discussion (1)

Collapse
idarek profile image
Dariusz Więckiewicz

As you write this with #wordpress tag, than for wordpress users is wasier to install Redirection plugin, create group of redirections that will write them in .htaccess (if you using Apache server, not Ngynx) and you using .htaccess approache with user friendly interface with additional options.