WebFaction
Community site: login faq

This is probably an Apache ABC but I do not see the light. I want to my Django admin pages served in https, but only the admin pages. This implies:

  • Redirect http://my_site/admin/* to https://my_site/admin/*.
  • Redirect all traffic that is https but not part of https://my_site/admin back to http.

After googling I created the following apache rewrite rules

RewriteCond %{HTTPS} off 
RewriteRule ^/?(admin.*) https://%{SERVER_NAME}/$1 [R, L] 
RewriteCond %{HTTPS} on 
RewriteRule !^/?(admin.*) http://%{SERVER_NAME}/$1 [R, L]

Result: Going to http://my_site/admin redirects to https://my_site/admin (hurray) and the browser gives message Error code: ERR_TOO_MANY_REDIRECTS, this webpage has a redirect loop.

Does anybody have a hint where I am wrong? Below the full httpd.conf (made anonymous)

Thanks in advance, Arjan.

ServerRoot "/home/my_account/webapps/my_app/apache2"

LoadModule dir_module        modules/mod_dir.so
LoadModule env_module        modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module       modules/mod_mime.so
LoadModule rewrite_module    modules/mod_rewrite.so
LoadModule setenvif_module   modules/mod_setenvif.so
LoadModule wsgi_module       modules/mod_wsgi.so

RewriteEngine On
RewriteLog "/home/my_account/logs/user/rewrite.log"

RewriteCond %{HTTPS} off
RewriteRule ^/?(admin.*) https://%{SERVER_NAME}/$1 [R, L]
RewriteCond %{HTTPS} on
RewriteRule !/?(admin.*) http://%{SERVER_NAME}/$1 [R, L]

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/my_account/logs/user/access_my_account.log
ErrorLog /home/my_account/logs/user/error_my_account.log
KeepAlive Off
Listen 24047
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 5

WSGIDaemonProcess my_app processes=2 threads=12 python-path=/home/my_account/webapps/my_app:/home/my_account/webapps/my_app/my_app_folder:/home/my_account/webapps/my_app/lib/python2.7:/home/my_account/webapps/my_app/lib/python2.7/site-packages
WSGIProcessGroup my_app
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /home/my_account/webapps/my_app/my_app_folder/my_app_folder/wsgi.py

asked 06 Jan '14, 14:53

ArjandeK
111
accept rate: 0%


Using the https.conf tag I did find the solution myself: http://community.webfaction.com/questions/3211/apache-conf-http-and-https I am happy!

permanent link

answered 06 Jan '14, 15:45

ArjandeK
111
accept rate: 0%

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
×28

question asked: 06 Jan '14, 14:53

question was seen: 3,752 times

last updated: 06 Jan '14, 15:45

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