分类: LINUX
2005-08-05 16:19:09
OS X Server
HOW TO: redirect http requests to https
If you have set up a site using ssl all requests for that domain not preceded by https it will point to the defualt web site. If what is required is that all requests for the domain on port 80 go to the 443 or in other words all requests for http go to https, there are a number of ways of doing this (using htacces or other scripting), however the following is the method we prefer.
1 go to the site config file at /etc/httpd/sites/
cd /etc/httpd/sites/
open the config file (e.g. 0016_195.75.175.184_443_secure.example.com.conf) in pico and edit the section
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
adding the following condition and rule and either delete or comment out the existing conditions and rules.
RewriteCond %{SERVER_PORT} !443
RewriteRule (.*) https://secure.example.com/ [R]
so that it reads as
RewriteEngine On
## RewriteCond %{REQUEST_METHOD} ^TRACE
## RewriteRule .* - [F]
RewriteCond %{SERVER_PORT} !443
RewriteRule (.*) https://secure.example.com/ [R]
2. In server admin duplicate the site secure.example.com, turn the web service off, edit the new site changing (from general) the port from 433 to 80, and from secure turn Enable Secure Sockets Layer off. You will now have two site config files in /etc/httpd/sites/ (e.g 0016_195.75.175.184_443_secure.example.com.conf and 0016_195.75.175.184_80_secure.example.com.conf).
3 Restart the web service and all requests to http://secure.example.com will be automatically redirected to https://secure.example.com.
It may appear contradictory to have two sites with the same name but one is on port 80 and the other is on port 443, Apache does allow this configuration. This method allows you to treat all virtual sites on an individual basis, you may wish some to be accessed only via ssl and others to be accesses via ssl and non ssl.
Last updated 08/06/05 Bruce Robbins
Platform: Mac OS X Server 10.3 or later Further reading