Configure Apache for SSL
Introduction
This article shows how to configure apache to enable users to browse securely through SSL whilst restricting secure pages from search engines to eliminate duplicate content indexing.
Create an SSL Virtual Host
To setup your apache web server to allow your website access through port 443 (secure web port) you will need to add a virtual host to your ssl config file.
This file contains roughly the same contents as the httpd config file.
The http.conf and ssl.conf files can usually be found in the following locations:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/ssl.conf
Copy your virtual host block for the given website from the httpd.conf to the bottom of the ssl.conf, add the bold lines in following example and ensure the port is set to 443 not 80.
<VirtualHost 62.233.80.237:443>
ServerName www.sakuiweb.com
ServerAlias sakuiweb.com www.sakuiweb.com
DocumentRoot /home/sakuiweb.com/public_html
ErrorLog logs/sakuiweb.com-error_log
CustomLog logs/sakuiweb.com-access_log2 combined
SSLEngine on
SSLCertificateFile /certs/sakuiweb.com.crt
SSLCertificateKeyFile /certs/sakuiweb_com.key
</VirtualHost>
Block Search Engines From https Address
To achieve this you can add one line to you vitualhost in the httpd.conf to redirect search engines to another robots.txt file. Redirect 301 /robots_ssl.txt "http://www.sakuiweb.com/robots.txt" Also to ensure all calls to your standard virtualhost are allowed add the following to your virtualhost in the ssl.conf to redirect back. Redirect 301 /robots.txt "https://www.sakuiweb.com/robots_ssl.txt" At this stage it's a good idea to test your configuration, you can do this by navigating to one of your robots.txt files and toggling the url between http and https.
Redirecting https urls Already Indexed
You can paste the following code into a php main include file if you have one.
It relies on information provided by the server from the http request to provide a permanent redirect for google.
if((!(strpos($_SERVER['HTTP_USER_AGENT'],'Google')===false))&&$_SERVER['HTTPS']=='on')
{
$newurl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if(substr($newurl,strlen($newurl)-9,6)=='index.') {$newurl = substr($newurl,0,strlen($newurl)-9); }
if(isset($_SERVER['QUERY_STRING'])) {$newurl=$newurl."?".$_SERVER['QUERY_STRING']; }
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$newurl);
exit();
}
Comment
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sakuiwe1/public_html/articles/configure_apache_for_ssl/index.php on line 109
