Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Korveld/b01e8d7d8c6ae7258ac207e78bdfe8a5 to your computer and use it in GitHub Desktop.

Select an option

Save Korveld/b01e8d7d8c6ae7258ac207e78bdfe8a5 to your computer and use it in GitHub Desktop.
Redirect all pages to non-www and HTTPS in WordPress
# BEGIN Redirects
RewriteEngine On
# 301 redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# END Redirects
If you still want the www way instead https://www.example.com
# BEGIN Redirects
RewriteEngine On
# 301 redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# END Redirects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment