<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog &#124; edwards research &#187; httpd.conf</title>
	<atom:link href="http://blog.edwards-research.com/tag/httpd-conf/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.edwards-research.com</link>
	<description>some notes from our staff...</description>
	<lastBuildDate>Wed, 04 May 2011 02:11:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Force Apache2 to redirect from HTTP to&#160;HTTPS</title>
		<link>http://blog.edwards-research.com/2010/02/force-apache2-to-redirect-from-http-to-https/</link>
		<comments>http://blog.edwards-research.com/2010/02/force-apache2-to-redirect-from-http-to-https/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 11:55:22 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[web hosting]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://blog.edwards-research.com/?p=352</guid>
		<description><![CDATA[Want to redirect requests for http://www.yoursite.com to https://www.yoursite.com? There are many suggestions out there to add a .htaccess file with rewrite conditions[1] but I figured I&#8217;d suggest a second, through a simple change to your httpd.conf file (or if you are running Ubuntu or another distro that splits the httpd.conf file into multiple files, in [...]]]></description>
			<content:encoded><![CDATA[<p>Want to redirect requests for <strong>http://www.yoursite.com</strong> to <strong>https://www.yoursite.com</strong>?</p>
<p>There are many suggestions out there to add a .htaccess file with rewrite conditions[<a href="http://serverfault.com/questions/77831/how-to-force-ssl-https-on-apache-location" target="_blank">1</a>] but I figured I&#8217;d suggest a second, through a simple change to your httpd.conf file (or if you are running Ubuntu or another distro that splits the httpd.conf file into multiple files, in your <strong>/etc/apache2/sites-available/{yoursite}</strong> configuration file. (If you are running a pretty Ubuntu install, the file is <strong>/etc/apache2/sites-available/default</strong>)</p>
<p>This technique still uses the rewrite engine (so you&#8217;ll need <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html" target="_blank">mod_rewrite</a> module) but it places the configuration in the httpd.conf file (or its equivalent) and out of the .htaccess file.  There are many reasons you might want to do this, such as prevent it from being changed (many site configurations allow users to edit all .htaccess files but prevent them from editing the httpd.conf file) or to prevent it from being overwritten by certain web application packages (many application packages including WordPress and MediaWiki employ custom .htaccess files to provide more friendly URLs).</p>
<p>The change is simple, in your httpd.conf file, change the following part of your virtual host section:</p>
<pre class="brush: plain; title: ;">
&lt;VirtualHost *:80&gt;
        ServerAdmin contact@yourwebsite.com

        DocumentRoot /var/www/public

        &lt;Directory /&gt;
</pre>
<p>&#8230; to something resembling the following:</p>
<pre class="brush: plain; title: ;">
&lt;VirtualHost *:80&gt;
        RewriteEngine on
        ReWriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
&lt;/VirtualHost&gt;

&lt;VirtualHost *:443&gt;
        ServerAdmin contact@yourwebsite.com

        DocumentRoot /var/www/public

        SSLEngine On
        SSLCertificateFile    /etc/apache2/ssl/mycert.pem
        SSLCertificateKeyFile /etc/apache2/ssl/mycert.key

        &lt;Directory /&gt;
</pre>
<p>The important things here are that the port 80 <a href="http://httpd.apache.org/docs/2.0/vhosts/" target="_blank">Virtual Host</a> has been changed to listen on port 443 (Line 7), there is a new Virtual Host that has been added above our existing Virtual Host that is set to listen on port 80 and only contains the rewrite code (Lines 1-5), and finally, there are lines added that enable and configure the <a href="http://httpd.apache.org/docs/2.0/mod/mod_ssl.html" target="_blank">SSLEngine</a> (settings may differ based on implementation)(Lines 12-14).</p>
<p>Restart Apache and your browser should redirect requests to <strong>http://www.yoursite.com/</strong> to <strong>https://www.yoursite.com</strong>.  In case you&#8217;re wondering, a request for <strong>http://www.yoursite.com/staff/about.php</strong> will also redirect to <strong>https://www.yoursite.com/staff/about.php</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.edwards-research.com/2010/02/force-apache2-to-redirect-from-http-to-https/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

