How to redirect HTTPS to HTTP and www to non-www URL with .htaccess:
-
First make sure
HTTPSis working and valid. It’s easy (and free) to do with Let’s Encrypt these days.Note: Although you are redirecting
HTTPStoHTTP, I’d recommend doing it the opposite, i.e.HTTPtoHTTPS. Better for Security, SEO & Browser compatibility – popular browsers are increasingly making it difficult forHTTPsites. -
Then make sure
.htaccessandmod_rewritemodule is working. -
Then use the following CODE in the
.htaccessfile of your web root directory (if you are already using some rules there, adjust them accordingly with these new rules):<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} =on [OR] RewriteCond %{HTTP_HOST} !^example\.com$ RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L] # remaining htaccess mod_rewrite CODE for WordPress </IfModule>Note: Replace
example.comwith your own domain name.
Why .htaccess solution is better:
It’s better to do these sort of redirects with the web server. From your question, since your web server seems to be Apache, it’s better to do with .htaccess. Why:
- It’s faster.
- Your
functions.phpfile remains cleaner & does what it’s originally there for, i.e. Theme modifications. - Changing the theme will not affect this.
- For every redirect, the entire WordPress codebase doesn’t have to load twice – once before redirect & then after redirect.