Insomnophobia
Insomnophobia

Reputation: 633

htaccess rule not redirecting to https as expected

So, this seems like it should be fairly straight forward, if the request is not https or the request uses the www prefix redirect to https with out www. Using the following rewrite rule seems like it should accomplish both of the following, but for some reason does not. Any suggestions?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.domain\.org [NC,OR]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*) https://domain.org/$1 [R=301,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


</IfModule>

# END WordPress

Upvotes: 0

Views: 45

Answers (1)

Panama Jack
Panama Jack

Reputation: 24448

Make sure rewrite engine is on and that you have have AllowOverride set to All in apache config. Try it this way and see if it works. I use this exact code for my site and it works perfectly.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.org [NC,OR]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*) https://domain.org/$1 [R=301,L]

Upvotes: 1

Related Questions