1

I hope someone might be able to help with this.

My site crawl is showing that I have a redirect chain on my home page. Basically it shows I am going from :

http: > https: > https://www.

I need everything to go from http:// and http://www directly to https://www. without the chain.

Below is a copy of the .htaccess, can anyone see if there is an error in there that could be causing it.

</IfModule>

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# 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

In addition, I have seen that they have a plugin called

SSL insecure content fixer installed.

It is showing this under its status:

Array (
[HTTPS] => on
[PHPHANDLER] => /usr/local/php70/bin/php
[HTTP_X_REAL_IP] => 109.158.20.158
[HTTP_X_FORWARDED_PROTO] => https
)

I think possibly this might have something to do with the issue, any thoughts are appreciated.

3
  • I don't see any details on how the example.com -> www.example.com redirect happens, can you describe how that's implemented?
    – Tom J Nowell
    Jul 16 '18 at 16:59
  • to be honest the whole thing is confusing me. aside from the standard wordpress settings and the htaccess, i cannot see how most of the redirects are happening. The SSL is installed via siteground letsencrypt. but it does have https enforce and rewrite external links Jul 16 '18 at 17:10
  • So it could be your WP installation redirecting to www or even siteground doing it
    – Tom J Nowell
    Jul 16 '18 at 17:27
0

The non-www to www redirect is most certainly being handled (later) by WordPress. Your existing redirect in .htaccess is HTTP to HTTPS only, on the same host - which is actually the preferred (read: necessary) way if you have any plans to implement HSTS in the near future. So, this is not necessarily an "error".

However, to avoid the double redirect, you can incorporate the non-www to www redirect into your existing .htaccess rule. For example:

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

If you particularly want a generic (any domain) solution, without hardcoding the domain, then you could do something like the following instead:

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

Where %1 is a backreference to the host name (less any www. prefix) in the last matched CondPattern. Note, however, that without further modification this "generic" solution will also redirect subdomains.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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