Http to https is taking some time

Hello

I have successfully configured the SSL certificate for my client’s website.
Let me give you some technical information.
Website has been developed in Wordpress.
Server is from AWS with Ubuntu 16.04 with apache.

I have already entered .htaccess rules for the website.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force https:// for all except some selected URLs    
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/ticket-status/ [NC]
RewriteCond %{THE_REQUEST} !/servicerequest/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force http:// for selected URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /ticket-status/ [NC]
RewriteCond %{THE_REQUEST} /servicerequest/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

# END WordPress

<IfModule mod_expires.c>
  ExpiresActive On

  # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # Video
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/mpeg "access plus 1 year"

  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"

  # Others
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>

My problem is when I open the website it takes sometime to redirect from http to https and after that website works normally with good speed.
Let me know if I need to change something in above .htaccess code and/or I need to change/check something on server side too?

Any prompt feedback will be appreciated.

Regards

Bhargav

We’ll need to know your domain name to help in more detail.

Could you also run curl -vvv http://<YOUR_DOMAIN> and post the output?

Hi,

What does this part used for?

If it would result in all redirects to https reguardlessly, why not just use a universal redirect?

Thank you

Can you please give me a specific code which I can just replace with my code?

Hi @bhargav_webtech

the redirect isn't the problem. Your page is slow, very slow.

D:\temp>download http://www.cera-india.com/ -h
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Length: 319
Content-Type: text/html; charset=iso-8859-1
Date: Wed, 31 Oct 2018 16:14:19 GMT
Location: https://www.cera-india.com/
Server: Apache/2.4.18 (Ubuntu)

Status: 301 MovedPermanently

352,52 milliseconds
0,35 seconds

0,35 seconds to send back the redirect. This isn't a problem. But:

D:\temp>download https://www.cera-india.com/ -h
SSL-Zertifikat is valide
Pragma: no-cache
Link: https://www.cera-india.com/wp-json/; rel="https://api.w.org/",https://www.cera-india.com/; rel=shortlink
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Type: text/html; charset=UTF-8
Date: Wed, 31 Oct 2018 16:14:31 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Set-Cookie: PHPSESSID=pl2dm38hfoom385o958requbu2; path=/
Server: Apache/2.4.18 (Ubuntu)

Status: 200 OK

39662,07 milliseconds
39,66 seconds

39 seconds is really bad. Now checked again - 1,29 seconds.

1 Like

Nice find, @JuergenAuer! @bhargav_webtech, one thing that makes this confusing is that your browser will display “redirecting to https://www.cera-india.com/” while it is waiting for an answer on the HTTPS URL. But that doesn’t mean the redirect is slow, it means the target of the redirect (your website) is slow.

You can test this out yourself. Load https://www.cera-india.com/ (the HTTPS version) directly in your web browser. You will see that it is slow even without the redirect.

I don’t know if this has an impact on your web server delay but got this from Apache.org.

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.

1 Like

Agreed, however I would say (his issue) is more likely a general server slow (misconfigured) rather than the use of htaccess.

Thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.