WebFaction
Community site: login faq

I'm trying to force HTTPS on a subdirectory, but end up with a redirect loop.

Here's template I'm using in the .htaccess file that resides in the subdirectory:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} subdirectory
RewriteRule ^(.*)$ https://domain.com/subdirectory/$1 [R,L]

My suspicion is there's an issue with either the server port or the fact that Nginx is in the mix.

Anyone have this successfully working on Webfaction?

Thanks so much!

asked 23 Nov '13, 13:34

cliquenoir
14
accept rate: 0%


I think that using %{SERVER_PORT} is the wrong approach since Apache never receives HTTPS traffic - that's handled by the front-end Nginx server. Therefore, %{SERVER_PORT} is always 80, even for HTTPS traffic, and this will result in an infinite redirect loop.

The correct way to do this is to use %{HTTP:X-Forwarded-SSL}, something like this related community post. Hope that helps!

permanent link

answered 23 Nov '13, 18:51

ryans ♦♦
5.0k93360
accept rate: 43%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×76
×75
×2

question asked: 23 Nov '13, 13:34

question was seen: 2,248 times

last updated: 23 Nov '13, 18:51

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM