htaccess - How To Fix A Redirect Chain

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. Ba

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
  • I don't see any details on how the example -> www.example redirect happens, can you describe how that's implemented? – Tom J Nowell Commented Jul 16, 2018 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 – user2868832 Commented Jul 16, 2018 at 17:10
  • So it could be your WP installation redirecting to www or even siteground doing it – Tom J Nowell Commented Jul 16, 2018 at 17:27
Add a comment  | 

1 Answer 1

Reset to default 1

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\
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

相关推荐

  • htaccess - How To Fix A Redirect Chain

    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. Ba

    14小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信