Reputation: 1
Good morning, everyone! I am trying to use htaccess in my Wordpress site hosted through AWS to redirect http -> https, and www. -> non-www., like so: http://www.example.com to https://example.com.
Currently, the http to https redirect is working as intended. However, "www." is not being stripped from my urls, i.e http://www.example.com becomes https://www.example.com
Note: I for other redirects, I use the Redirection plugin. Furthermore I use Really Simple SSL plugin for https.
I have tried multiple variations of the redirect code, clearing my cache, checking it with incognito, etc.
Here is the current code I am using:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any advice would be greatly appreciated! Thank you!
Upvotes: 0
Views: 194
Reputation: 422
you could try this way:
###START MOD_REWRITE
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#REDIRECT ALL www REQUESTS OF YOUR SITE TO THE non-www VERSION AND http -> https
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteCond %{HTTP_HOST} !(\.dev|staging)
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
</IfModule>
###END MOD_REWRITE
###BEGIN WORDPRESS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
###END WORDPRESS
Leaving the default WordPress instructions you should not have any problem, let me know
Upvotes: 1