1

I just updated my WordPress site to a full SSL certificate. Everything is working as expected. Only 1 issue I can't solve.

After the update I noticed the homepage is being redirected as expected but subpages are all redirected to the homepage as well.

  • http://www.example.com is being redirected to https://www.example.com
  • http://example.com is being redirected to https://www.example.com
  • http://www.example.com/page is being redirected to https://www.example.com (I would like this to be https://www.example.com/page)

I am using my .htaccess file to get this to work. I think I am missing something.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
</IfModule>

1 Answer 1

0

You've put the HTTP to HTTPS (and canonical www) redirect in the wrong place. It should go before the WordPress front-controller. In fact, it should go before the # BEGIN WordPress section to avoid any chance of it being overwritten by WordPress in future updates.

To be honest, I'm a bit surprised that redirect would actually do anything (except for requests to static resources)? (Maybe you are seeing a cached redirect, or maybe WP itself is later redirecting to the home page?)

For example:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]

# 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

That redirect should ultimately be a 301 (permanent) redirect. So change R to R=301 once you have confirmed it's working OK.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.