Created
December 20, 2021 14:55
-
-
Save Korveld/b01e8d7d8c6ae7258ac207e78bdfe8a5 to your computer and use it in GitHub Desktop.
Redirect all pages to non-www and HTTPS in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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