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.
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.
Share Improve this question edited Jul 16, 2018 at 19:03 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Jul 16, 2018 at 16:37 user2868832user2868832 352 silver badges5 bronze badges 3 |1 Answer
Reset to default 1The 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\
RewriteRule .* https://www.example%{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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745096461a4611006.html
www
or even siteground doing it – Tom J Nowell ♦ Commented Jul 16, 2018 at 17:27