LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 06-01-2009, 06:30 PM   #1
mehoggan
LQ Newbie
 
Registered: May 2009
Posts: 4

Rep: Reputation: 0
How do you properly redirect all web client requests from http to https?


I have tried several things (one of which are included in my httpd.conf file below). However, no matter what I try when ever someone trys to get web pages from my server, they are returned using http, rather than https, and I want them returned using SSL. If you type https://www.geoginfo.com you will get to my index.html, and any subsequent page you can access via https://www.geoginfo.com/(the file or directory you want). However I don't want clients to manually have to do this. I would like them to be redirected. So below is my httpd.conf, please let me know what I need to change, or where I am going wrong. Thank you. (If you need more information please let me know)

<-----START HTTPD.conf----->
### Section 1: General Settings
Include conf.d/*.conf

ServerTokens OS
ServerRoot "/etc/httpd"
PidFile run/httpd.pid
Listen 192.168.1.1:80
Listen 192.168.1.1:443

<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>

<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

### Section 2: Main Settings
#Apache Directives
User apache
Group apache
AddType application/x-httpd-php .php .php4 .php5#.html .htm
AddHandler php5-script .php
TypesConfig /etc/mime.types
DefaultType text/plain
AddDefaultCharset ISO-8859-1
LogLevel warn

#SSL Directives
SSLRandomSeed startup file:/dev/urandom 1024
SSLRandomSeed connect file:/dev/urandom 1024
SSLSessionCache shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout 300
SSLPassPhraseDialog builtin
SSLMutex default
SSLCryptoDevice builtin

### Section 3: Virtual Hosts
NameVirtualHost 192.168.1.1:80

<VirtualHost www.geoginfo.com:80>
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{www.geoginfo.com}$1 [L,R]
RewriteLogLevel 2
ServerAdmin mehoggan@gmail.com
ServerName www.geoginfo.com:80
DocumentRoot "/mnt/data/geoginfo"
DirectoryIndex index.html index.php
ErrorLog logs/error_log

<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>

<Directory "/mnt/data/geoginfo">
Options Indexes FollowSymLinks
AllowOverride AuthConfig FileInfo
#AllowOverride None
Order allow,deny
Allow from all
</Directory>

AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
</VirtualHost>

NameVirtualHost 192.168.1.1:443

<VirtualHost www.geoginfo.com:443>
ServerAdmin mehoggan@gmail.com
ServerName www.geoginfo.com:443

DocumentRoot "/mnt/data/geoginfo"
DirectoryIndex index.html index.php

<Directory />
Options +Indexes FollowSymLinks
AllowOverride None
SSLRequireSSL
</Directory>

<Directory "/mnt/data/geoginfo">
Options Indexes FollowSymLinks
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>

AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

# SSL Configuration Part

ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

SSLEngine on
SSLOptions +StrictRequire

SSLProtocol all +SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW

SSLCertificateFile /etc/httpd/conf/server.crt
SSLCertificateKeyFile /etc/httpd/conf/server.key

AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl

SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0

<Files ~ "\.(cgi|shtml|phtml|php3?)$">
SSLOptions +StdEnvVars
</Files>

<Directory "/var/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
 
Old 06-01-2009, 06:46 PM   #2
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Haven't read you whole post, but here's the rule I use for one virtualhost

RewriteRule ^.*$ https://webmail.example.com [R,L]
 
Old 06-01-2009, 11:27 PM   #3
mehoggan
LQ Newbie
 
Registered: May 2009
Posts: 4

Original Poster
Rep: Reputation: 0
I am assuming that I was supposed to replace the domain name in your example with mine. With that assumption I tried your advice, by adding:

RewriteRule ^.*$ https://www.geoginfo.com [R,L]

AND OR

RewriteRule ^.*$ https://geoginfo.com [R,L]

to the httpd.conf file inside the virtual host which is directed towards port 80 or HTTP. I restarted Apache and then attempted to visit my site by typing www.geoginfo.com in the browser URL text box, hoping that I would be redirected to https://www.geoginfo.com or https://geoginfo.com, however I am sent to plain text non-secure http://www.geoginfo.com whenever I visit my website.

Once again if I manually type https://www.geoginfo.com or https://geoginfo.com into the browser URL text box it will take me to the secure version. However, I would like all paged to be directed automatically to https.

Please help I need to get the project off the ground in about a week and I am totally stumped.
 
Old 06-01-2009, 11:42 PM   #4
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
I'll post the full virtualhost definitions later.
 
Old 06-02-2009, 03:49 AM   #5
chitambira
Member
 
Registered: Oct 2008
Location: Fife
Distribution: RHEL, Centos
Posts: 373
Blog Entries: 1

Rep: Reputation: 49
<VirtualHost *:80>
RewriteEngine On
RewriteCond ^{HTTPS} !on
RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [R,QSA,L]
</VirtualHost>

<VirtualHost *:443>
.
.
# Check for geoginfo.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*geoginfo.com$
RewriteRule .* - [E=YOURDOMAIN:geoginfo.com]
.
.
</VirtualHost>
 
  


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
redirect all http requests to a different squid proxy server r2d2#jedi Linux - Networking 1 05-27-2009 12:31 AM
How to redirect http to https? Sovan Linux - Server 1 12-03-2008 01:11 PM
redirect http to https awreneau Linux - Server 17 10-14-2008 09:13 AM
redirect some http requests to port 443. FMH Linux - Software 5 09-17-2007 08:19 AM
redirect SquirrelMail from http to https using Apache2 cccc Linux - Server 3 09-23-2006 10:02 AM


All times are GMT -5. The time now is 06:09 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration