LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-10-2011, 02:11 AM   #1
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467
Blog Entries: 60

Rep: Reputation: 51
.htaccess / https / fcgi


Hi. For one project I use a web hosting service. I wanted the entire site to be https, so I bought a service from them in which they automatically install a trusted cert so people can access the site through https protocol. Since http is still available, though, I need to do automatic rewrites or something to change http into https requests. (I don't have access to their Apache server configuration files or anything like that.)

I found on the net this code to add to my .htaccess file:

Code:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
However, I already have this in my .htaccess file, for my Ruby app:

Code:
# General Apache options
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)/!$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
ErrorDocument 500 "Application error Application failed to start properly"
Whenever I try to integrate the two there are bad results; it seems that it somehow changes the programming so that all requests end up being handled by the dispatch script, rather than only requests that don't specify a static file. Could someone who understands how .htaccess files work recommend a solution?
 
Old 03-10-2011, 08:52 PM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
One thing I notice is that you don't have the "RewriteEngine On"
directive before the RewriteCond. The fix might be as simple as
adding one line.
 
Old 03-11-2011, 04:57 PM   #3
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,217
Blog Entries: 1

Rep: Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070
Hi,

You should put those 2 lines just under the RewriteEngine directive, so everything turns into https before the rest of the rewrite directives is processed.

Regards
 
Old 03-12-2011, 12:51 AM   #4
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467

Original Poster
Blog Entries: 60

Rep: Reputation: 51
Not /precisely/ sure, but it seems that there was something wrong with the syntax. This worked fine (after the 'RewriteEngine On' line):

Code:
RewriteCond %{HTTPS} !=on
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is different between perl-fcgi i FCGIperl? centosfan Linux - Server 2 08-06-2009 08:39 PM
APC user cache with fcgi processes walidaly Linux - Server 0 07-21-2007 02:43 AM
PHP5 under lighttpd with fcgi walidaly Linux - Software 5 03-17-2007 11:57 PM
https , htaccess and apache 2 :) unkn0wn Linux - Networking 1 05-07-2006 07:38 PM
Apache2 php5 (cgi-fcgi). hgb Linux - Software 2 11-16-2005 10:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration