Title: HTTPS redirect loop
Last modified: August 30, 2016

---

# HTTPS redirect loop

 *  Resolved [rautamik](https://wordpress.org/support/users/rautamik/)
 * (@rautamik)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/https-redirect-loop-3/)
 * I’m trying to setup WordPress blog to subfolder on domain using SSL without success.
   If the blog .htaccess is set to redirect all HTTP to HTTPS then it results redirect
   loop. If .htaccess is not set to redirect all HTTP to HTTPS then blog is not 
   showing properly as browser is blocking all HTTP requests as SSL is in use, also
   wp logins are failing in this case.
 *     ```
       Details:
       - Fresh WordPress installation
       - Domain is using SSL
       - WP installed on subfolder example.com/blog/
       - HTTPS set to WP's home and site URL in database
       ```
   
 * Here is the blog folder .htaccess
 *     ```
       <IfModule mod_rewrite.c>
       RewriteEngine On
   
       RewriteCond %{SERVER_PORT} !^443$
       RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
   
       RewriteBase /blog/
       RewriteRule ^index\.php$ - [L]
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule . /blog/index.php [L]
       </IfModule>
       ```
   
 * Here is the main domain .htaccess:
 *     ```
       Options +FollowSymLinks
       RewriteEngine On
       RewriteBase /
   
       RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
       RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
   
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteCond %{REQUEST_URI} !\..+$
       RewriteRule ^(.*)$ http://foobar.example.com/$1 [L,R=301]
       ```
   
 * Here is apache config for http requests: /etc/apache2/sites-available/000-default.
   conf
 *     ```
       <VirtualHost *:80>
          ServerName example.com
          ServerAlias *.example.com
          ServerSignature Off
          RewriteEngine on
          RewriteCond %{HTTPS} !=on
          RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
       </VirtualHost>
       ```
   
 * Any help and ideas what to check would be highly appreciated.

Viewing 1 replies (of 1 total)

 *  Thread Starter [rautamik](https://wordpress.org/support/users/rautamik/)
 * (@rautamik)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/https-redirect-loop-3/#post-6352046)
 * I was able to resolve the problem by adding $_SERVER[‘HTTPS’]=’on’; into wp-config.
   php. I don’t know why $_SERVER[‘HTTPS’] is not set properly by the system, but
   I guess its somehow related to Apache/SSL configurations.
 * Without setting $_SERVER[‘HTTPS’]=’on’ WP was not able to detect HTTPS and was
   loading content over HTTP which with .htacccess redirects caused redirect loop.

Viewing 1 replies (of 1 total)

The topic ‘HTTPS redirect loop’ is closed to new replies.

## Tags

 * [HTTPS](https://wordpress.org/support/topic-tag/https/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [rautamik](https://wordpress.org/support/users/rautamik/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/https-redirect-loop-3/#post-6352046)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
