<p>Think we figured out the root cause of this - we have a load balancer in front of our origin server and, long story short, that load balancer was communicating with our origin server via HTTP, causing the extra http redirect. </p>

<p>Fixing that issue would be a long and arduous process so, through some infrastructure updates, we'll be moving away from using the load balancer entirely. </p>

CC BY-SA 3.0
2017-06-02T19:14:34.130Z
2017-06-02T19:14:34.130Z
dpayne
<p>So I've updated the site URL in my general.php as follows:</p>

<pre><code>    'siteUrl' =&gt; "https://" . $_SERVER['HTTP_HOST'],
</code></pre>

<p>I also have our web server making sure everything goes to <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a>. Our IT person set this up but as I understand it it's done through vhosts in Apache. </p>

<p>Here is our .htaccess file:</p>

<pre><code>&lt;IfModule mod_expires.c&gt;
 ExpiresActive on
 # Perhaps better to whitelist expires rules? Perhaps.
 ExpiresDefault "access plus 1 month"
 # cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
 ExpiresByType text/cache-manifest "access plus 0 seconds"
 # Your document html
 ExpiresByType text/html "access plus 0 seconds"
 # Data
 ExpiresByType text/xml "access plus 0 seconds"
 ExpiresByType application/xml "access plus 0 seconds"
 ExpiresByType application/json "access plus 0 seconds"
 # Feed
 ExpiresByType application/rss+xml "access plus 1 hour"
 ExpiresByType application/atom+xml "access plus 1 hour"
 # Favicon (cannot be renamed)
 ExpiresByType image/x-icon "access plus 1 week"
 # Media: images, video, audio
 ExpiresByType image/gif "access plus 1 month"
 ExpiresByType image/png "access plus 1 month"
 ExpiresByType image/jpeg "access plus 1 month"
 ExpiresByType video/ogg "access plus 1 month"
 ExpiresByType audio/ogg "access plus 1 month"
 ExpiresByType video/mp4 "access plus 1 month"
 ExpiresByType video/webm "access plus 1 month"
 # Webfonts
 ExpiresByType application/x-font-ttf "access plus 1 month"
 ExpiresByType font/opentype "access plus 1 month"
 ExpiresByType application/x-font-woff "access plus 1 month"
 ExpiresByType image/svg+xml "access plus 1 month"
 ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
 ExpiresByType text/css "access plus 1 year"
 ExpiresByType application/javascript "access plus 1 year"
&lt;/IfModule&gt;

&lt;IfModule mod_deflate.c&gt;
 AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
 AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
 Addtype font/opentype .otf
 Addtype font/truetype .ttf
 AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.msfontobject application/x-font-ttf font/opentype font/truetype
&lt;/IfModule&gt;

&lt;IfModule mod_rewrite.c&gt;
     RewriteEngine On

    #301 redirect with trailing slash
        RewriteCond %{REQUEST_URI} /+[^\.]+$
        RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

    #Send would-be 404 requests to Craft
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
        RewriteRule (.+) index.php?p=$1 [QSA,L]
  AddType text/x-component .htc

&lt;/IfModule&gt;
</code></pre>

<p>However, in tracking how redirects are working, it looks like most redirects, including adding an extra / to the end of a URL via the .htaccess, those done in Craft templates themselves and those done through the <a href="https://straightupcraft.com/craft-plugins/redirect-manager" rel="nofollow noreferrer">redirect manager plugin</a> 301 to <a href="http://www.example.com" rel="nofollow noreferrer">http://www.example.com</a> and then 301 again to <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a>. Visits to <a href="http://www.example.com" rel="nofollow noreferrer">http://www.example.com</a> redirect straight to <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a> and visits to https pages directly return a 200.</p>

<p>How can I configure Craft to out the first redirect to http and just go straight to https? Thanks!</p>

CC BY-SA 3.0
2017-06-01T20:55:38.103Z
What does your public `.htaccess` file look like?  I assume you're doing a https rewrite there?
Brad Bell
CC BY-SA 3.0
2017-06-01T22:13:46.283Z
@BradBell Just shared .htaccess file. Doing redirects in Apache, I believe via our Vhosts set-up.
dpayne
<templating><redirect><htaccess><apache><https>
HTTPs Site - Redirects Go to HTTP First & Then HTTPs
# HTTPs Site - Redirects Go to HTTP First & Then HTTPs

(Asked by: username_0 on 2017-06-01)

So I've updated the site URL in my general.php as follows:
    'siteUrl' => "https://" . $_SERVER['HTTP_HOST'],

I also have our web server making sure everything goes to https://www.example.com. Our IT person set this up but as I understand it it's done through vhosts in Apache. 
Here is our .htaccess file:

 ExpiresActive on
 # Perhaps better to whitelist expires rules? Perhaps.
 ExpiresDefault "access plus 1 month"
 # cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
 ExpiresByType text/cache-manifest "access plus 0 seconds"
 # Your document html
 ExpiresByType text/html "access plus 0 seconds"
 # Data
 ExpiresByType text/xml "access plus 0 seconds"
 ExpiresByType application/xml "access plus 0 seconds"
 ExpiresByType application/json "access plus 0 seconds"
 # Feed
 ExpiresByType application/rss+xml "access plus 1 hour"
 ExpiresByType application/atom+xml "access plus 1 hour"
 # Favicon (cannot be renamed)
 ExpiresByType image/x-icon "access plus 1 week"
 # Media: images, video, audio
 ExpiresByType image/gif "access plus 1 month"
 ExpiresByType image/png "access plus 1 month"
 ExpiresByType image/jpeg "access plus 1 month"
 ExpiresByType video/ogg "access plus 1 month"
 ExpiresByType audio/ogg "access plus 1 month"
 ExpiresByType video/mp4 "access plus 1 month"
 ExpiresByType video/webm "access plus 1 month"
 # Webfonts
 ExpiresByType application/x-font-ttf "access plus 1 month"
 ExpiresByType font/opentype "access plus 1 month"
 ExpiresByType application/x-font-woff "access plus 1 month"
 ExpiresByType image/svg+xml "access plus 1 month"
 ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
 ExpiresByType text/css "access plus 1 year"
 ExpiresByType application/javascript "access plus 1 year"



 AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
 AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
 Addtype font/opentype .otf
 Addtype font/truetype .ttf
 AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.msfontobject application/x-font-ttf font/opentype font/truetype



     RewriteEngine On

    #301 redirect with trailing slash
        RewriteCond %{REQUEST_URI} /+[^\.]+$
        RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]

    #Send would-be 404 requests to Craft
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
        RewriteRule (.+) index.php?p=$1 [QSA,L]
  AddType text/x-component .htc



However, in tracking how redirects are working, it looks like most redirects, including adding an extra / to the end of a URL via the .htaccess, those done in Craft templates themselves and those done through the redirect manager plugin 301 to http://www.example.com and then 301 again to https://www.example.com. Visits to http://www.example.com redirect straight to https://www.example.com and visits to https pages directly return a 200.
How can I configure Craft to out the first redirect to http and just go straight to https? Thanks!

**Tags:** templating, redirect, htaccess, apache, https

> **Comments:**
> **username_1**: What does your public `.htaccess` file look like?  I assume you're doing a https rewrite there?  
> **username_0**: @BradBell Just shared .htaccess file. Doing redirects in Apache, I believe via our Vhosts set-up.  

---

## 1 answers

### Answer by username_0 on 2017-06-02. Score: 1 | Accepted answer

Think we figured out the root cause of this - we have a load balancer in front of our origin server and, long story short, that load balancer was communicating with our origin server via HTTP, causing the extra http redirect.

Fixing that issue would be a long and arduous process so, through some infrastructure updates, we'll be moving away from using the load balancer entirely.


---

