WebFaction
Community site: login faq
0
2

I need a bit more control over which URLs of my site are served via HTTP and HTTPS. In my WebFaction control panel, I've two website records that are identical except that one has HTTPS enabled and the other does not.

However, I'm having trouble with my httpd.conf. I want it to do two things: 1) redirect all www to the corresponding non-www counterparts; and 2) redirect all requests for a particular URL path to HTTPS and vice-versa, all requests not to that folder are served via HTTP.

For example, this will redirect all www to non-www:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^/(.*)$ http://example.com/$1 [R=301,L]

But this attempt at securing a particular path results in an infinite loop:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/secure/.*
RewriteRule ^/(.*)$ https://example.com/$1 [R=301,L]

I feel I must be missing something pretty obvious like some VirtualHost directives for both the secure and non-secure sites, but I don't know what those should be. Or if this can all be accommodated in a single httpd.conf. Any insight would be greatly appreciated. Thanks, Dominic

asked 17 Apr '11, 20:53

dbruno
324
accept rate: 0%


I believe you should be able to achieve this effect with something like this:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

In this case, we're getting the HTTP_HOST directly from the request, but you can substitute example.com or add any other necessary conditionals.

Hope that helps!

permanent link

answered 17 Apr '11, 21:13

ryans ♦♦
5.0k93260
accept rate: 43%

ryans, thanks so much - the %{HTTP:X-Forwarded-SSL} was exactly what I was looking for. It's all working now.

(17 Apr '11, 21:27) dbruno

Hi, on askapache ( http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html ) I have read that the solution above is for servers where is not enabled (or we are not sure is enabled) mod_ssl, while if that module is loaded should be preferred "SSLOptions +StrictRequire" and following. Do you agree? Does WebFaction use mod_ssl for https sites? Thanks

(05 Mar '12, 06:35) robertotra
1

We are using our frontend nginx server for SSL termination, so apache's mod_ssl is not being used, but nginx's SSL module

(05 Mar '12, 10:42) iliasr ♦♦

Ok, thanks

(05 Mar '12, 12:56) robertotra
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:

×225
×28
×5

question asked: 17 Apr '11, 20:53

question was seen: 7,272 times

last updated: 05 Mar '12, 12:57

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