<?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>Edward A. Webb (.com) &#187; apache</title>
	<atom:link href="http://edwardawebb.com/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://edwardawebb.com</link>
	<description>get all his digital goodness 24/7</description>
	<lastBuildDate>Sat, 28 Jan 2012 17:46:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Migrate from Apache to nginx (and keep rewrites intact)</title>
		<link>http://edwardawebb.com/site-news/migrate-apache-nginx-rewrites-intact</link>
		<comments>http://edwardawebb.com/site-news/migrate-apache-nginx-rewrites-intact#comments</comments>
		<pubDate>Thu, 28 Jan 2010 20:10:13 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[Site News]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://edwardawebb.com/?p=647</guid>
		<description><![CDATA[nginx is a very fast and very lightweight web server that can handle static HTML blazingly fast, and does very well with dynamic (PHP) content as well.   In fact the very site your viewing is running atop of nginx.  nginx isn't ideal for every server, and can't handle SVN or WebDAV among other protocols.  But for your average site, nginx is choice.

The trouble was that I have lots of site (like this one!) that rely on a myriad of rewrite rules and logic to direct users properly.  Because we lose the mod_rewrite provided by apache, we need to tell nginx about our rewrite rules.

Luckily the logic is very similar, and all expression based as before...]]></description>
			<content:encoded><![CDATA[<p><strong>nginx</strong> is a very fast and very lightweight web server that can handle static HTML blazingly fast, and does very well with dynamic (PHP) content as well.   In fact the very site your viewing is running atop of <a href="http://wiki.nginx.org/Main" rel="nofollow" title="Learn more about nginx"  target="_blank">nginx</a>.  nginx isn&#8217;t ideal for every server, and can&#8217;t handle SVN or WebDAV among other protocols.  But for your average site running PHP, Ruby or Django, <strong>nginx is choice</strong>.</p>
<p>The trouble was that I have lots of site (like this one!) that rely on a myriad of rewrite rules and logic to direct users properly.  <strong>Because we lose the mod_rewrite provided by apache, we need to tell nginx about our rewrite rules.</strong></p>
<p><strong> Luckily the logic is very similar, and all expression based as before&#8230;</strong></p>
<p><strong><span id="more-647"></span><br />
</strong></p>
<h3>create domain specific configuration</h3>
<p>The first step is creating directories for each site you want to customize.  Any file within this directory will be read into configuration when nginx starts or reloads.</p>
<p>/home/my_user/nginx/edwardawebb.com/wordpress.conf</p>
<h3>Harvest those .htaccess files</h3>
<p>next we turn to our existing rules as a launch pad for our new rewrite logic.</p>
<h4>your apache rule (from .htaccess)</h4>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</pre>
<h4>your new nginx config (into wordpress.conf)</h4>
<pre>
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?url=$1 last;
}
</pre>
<p><strong>Note the similarity!</strong></p>
<p>&#8221; if the path they are looking for does not exist, give them this path instead. &#8221;</p>
<p>The differences are subtle but important.  Apache assumed absolute paths in the created path, so index.php would be /index.php &#8211; but nginx does not make that assumption, so we need to explicitly include the root /.</p>
<h3>Got more rules to rewrite?</h3>
<p>I am actually finding nginx&#8217;s logic based syntax much easier to master than Apache&#8217;s.  You can specify rules for specific domains or servers, and use many variables including the user agent and</p>
<p><a href="http://nginx.org/en/docs/http/converting_rewrite_rules.html" rel="nofollow" title="Learn how to migrate more rewrite rules." >http://nginx.org/en/docs/http/converting_rewrite_rules.html</a></p>
<p><a href="http://wiki.nginx.org/NginxConfiguration" rel="nofollow" title="Learn how to conifgurwe the most common tools (wordpress, drupal, Passenger, python, etc)" >http://wiki.nginx.org/NginxConfiguration</a></p>
<h3>Reload nginx</h3>
<p>For any changes to take affect you will need to force nginx to reload.</p>
<p>sudo /etc/init.d/nginx reload</p>
<p>If you still have questions maybe it is because you have not read the page <a href="http://wiki.nginx.org/NginxConfiguration" rel="nofollow" title="How to configure ANYTHING on nginx" >here</a> &#8211; but please post your thoughts!</p>
]]></content:encoded>
			<wfw:commentRss>http://edwardawebb.com/site-news/migrate-apache-nginx-rewrites-intact/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Multiple SSL Domains on Apache without Unique IPs</title>
		<link>http://edwardawebb.com/web-development/multiple-ssl-domains-apache-unique-ips</link>
		<comments>http://edwardawebb.com/web-development/multiple-ssl-domains-apache-unique-ips#comments</comments>
		<pubDate>Tue, 01 Sep 2009 13:19:40 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://edwardawebb.com/?p=565</guid>
		<description><![CDATA[So you host 13 domains on one server and want SSL certs for each domain. The cost of unique IPs is an obstacle indeed, but what if you didn't need any unique IP addresses?


IMpossible you say? Not with the release of Apache 2.2.13!

I stumbled on this nice little feature called SNI (or Server Name Indication) that allows multiple domains to share an IP and implement SSL without showing warnings to users or confusing Apache. ]]></description>
			<content:encoded><![CDATA[<p>So you host 13 domains on one server and want SSL certs for each domain.  The cost of unique IPs is an obstacle indeed, but what if you didn&#8217;t need any unique IP addresses?</p>
<p>IMpossible you say? Not with the release of Apache 2.2.13!</p>
<p>I stumbled on this nice little feature called SNI (or <em>Server Name Indication</em>) that allows multiple domains to share an IP and implement SSL without showing warnings to users or confusing Apache.  I found this beauty after reading another great article on Linux Magazine, <a href="http://www.linux-mag.com/cache/7480/1.html" rel="nofollow"  target="_blank">Ten Things You Didn&#8217;t KNow Apache (2.2) Could Do </a></p>
<p>So those of you running your own servers can take advantage by upgrading today!</p>
<p>For those of you relying on a Host you should start bombarding them with requests immediately. <strong>DreamHost members can <a href="https://panel.dreamhost.com/index.cgi?tree=home.sugg&amp;category=_all&amp;search=Support%20for%20name-bas" rel="nofollow" title="Vote for this Feature on all DreamHost servers."  target="_blank">vote up the already created suggestion  to implement this</a>.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://edwardawebb.com/web-development/multiple-ssl-domains-apache-unique-ips/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Books I recommend</title>
		<link>http://edwardawebb.com/linux/books-recommend</link>
		<comments>http://edwardawebb.com/linux/books-recommend#comments</comments>
		<pubDate>Wed, 08 Jul 2009 21:43:13 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[Database Tips]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://edwardawebb.com/?p=509</guid>
		<description><![CDATA[Amazon.com Widgets]]></description>
			<content:encoded><![CDATA[<p><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" id="Player_2c0bc29f-ccdb-489a-ac1e-da93c888b804"  WIDTH="500px" HEIGHT="175px"> <PARAM NAME="movie" VALUE="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fedawe-20%2F8010%2F2c0bc29f-ccdb-489a-ac1e-da93c888b804&#038;Operation=GetDisplayTemplate"><PARAM NAME="quality" VALUE="high"><PARAM NAME="bgcolor" VALUE="#FFFFFF"><PARAM NAME="allowscriptaccess" VALUE="always"><embed src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fedawe-20%2F8010%2F2c0bc29f-ccdb-489a-ac1e-da93c888b804&#038;Operation=GetDisplayTemplate" id="Player_2c0bc29f-ccdb-489a-ac1e-da93c888b804" quality="high" bgcolor="#ffffff" name="Player_2c0bc29f-ccdb-489a-ac1e-da93c888b804" allowscriptaccess="always"  type="application/x-shockwave-flash" align="middle" height="175px" width="500px"></embed></OBJECT> <NOSCRIPT><a href="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fedawe-20%2F8010%2F2c0bc29f-ccdb-489a-ac1e-da93c888b804&#038;Operation=NoScript" rel="nofollow" >Amazon.com Widgets</a></NOSCRIPT></p>
]]></content:encoded>
			<wfw:commentRss>http://edwardawebb.com/linux/books-recommend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevent Image use by outside sites</title>
		<link>http://edwardawebb.com/web-development/prevent-image-sites</link>
		<comments>http://edwardawebb.com/web-development/prevent-image-sites#comments</comments>
		<pubDate>Fri, 02 Jan 2009 18:12:05 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[MIsc.Tips]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[hotlinking]]></category>
		<category><![CDATA[htaccess]]></category>

		<guid isPermaLink="false">http://edwardawebb.com/?p=273</guid>
		<description><![CDATA[Hotlinking&#8230; one of the most dastardly crimes to hit the internet.  This is especially concerning if your hosting plan caps your bandwidth. Hotlinking is when users insert a url to your images on their own site rather than linking to your page (or just uploading the image to their own servers) What is a simple [...]]]></description>
			<content:encoded><![CDATA[<p>Hotlinking&#8230; one of the most dastardly crimes to hit the internet.  This is especially concerning if your hosting plan caps your bandwidth.</p>
<p>Hotlinking is when users insert a url to your images on their own site rather than linking to your page (or just uploading the image to their own servers)</p>
<p><strong>What is a simple webmaster like yourself to do with these hooligans that are chewing away at your bandwidth allocations? Well block them of course.  The solution is simple and straightforward.</strong></p>
<p>Best of all you can even server up a humorous or fearful image to replace the one being hijacked.</p>
<h3><span id="more-273"></span>The problem:</h3>
<p>You innocently hosted a sweet background image or icon only to find that devilish designers or bloggers are hotlinking to the image within their own sites.</p>
<h3>The solution:</h3>
<p>Catch the incoming requests and instead return a static image that warns they have been caught in the act.  The image should be of minimal size to lower bandwidth consumption.</p>
<h3>Implementation:</h3>
<p>Again we will rely on the quintessential Apache Rewrite module to preform this task.</p>
<p>Open up the .htaccess file in your top-most directory and add the following snippet;</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">FilesMatch</span> <span style="color: #7f007f;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>(png|gif|jpg|jpeg|bmp)$&quot;</span>&gt;
<span style="color: #00007f;">SetEnvIfNoCase</span> Referer <span style="color: #7f007f;">&quot;^http://([^/]*<span style="color: #000099; font-weight: bold;">\.</span>)?example.com/&quot;</span> requested_locally=<span style="color: #ff0000;">1</span>
<span style="color: #00007f;">RewriteCond</span> %{ENV:requested_locally} !=<span style="color: #ff0000;">1</span>
<span style="color: #00007f;">RewriteRule</span> <span style="color: #7f007f;">&quot;.*&quot;</span> <span style="color: #7f007f;">&quot;/no-hotlink.gif&quot;</span> [L]
&lt;/<span style="color: #000000; font-weight:bold;">FilesMatch</span>&gt;</pre></div></div>

<p><strong>What&#8217;s all this then?</strong> Here&#8217;s a breakdown line by line;</p>
<ul>
<li>For any files that end with image extensions, use the following rules</li>
<li>Case insensitive check against the headers referrer sent by browser. (yes referrer is spelled wrong as it was in the original specs) If the referrer is your own, set an environmental variable to 1</li>
<li>If our environmental variable is not set (meaning its not a local request)</li>
<li>Then send them an ugly/funny/angry photo instead</li>
<li>end rules for files matching image extensions</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://edwardawebb.com/web-development/prevent-image-sites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forcing Visits to use SSL</title>
		<link>http://edwardawebb.com/web-development/forcing-visits-ssl</link>
		<comments>http://edwardawebb.com/web-development/forcing-visits-ssl#comments</comments>
		<pubDate>Thu, 01 Jan 2009 14:09:10 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://edwardawebb.com/?p=266</guid>
		<description><![CDATA[Intro Doesn&#8217;t matter whether it&#8217;s a CakePHP app for a client, your own personal CMS, or any other web based application. If your passing around passwords or other sensitive info you should really implement SSL. SSL provides 2 main perks to your visitors. First it encrypts all communication that flies across the web. This prevents [...]]]></description>
			<content:encoded><![CDATA[<h2>Intro</h2>
<p>Doesn&#8217;t matter whether it&#8217;s a CakePHP app for a client, your own personal CMS, or any other web based application. <strong>If your passing around passwords or other sensitive info you should really implement SSL.</strong> SSL provides 2 main perks to your visitors.</p>
<ul>
<li>First it encrypts all communication that flies across the web. This prevents curious or devious billies from getting your secrets.</li>
<li>Secondly it ensures to the user that your server is in fact who it claims, and not a nasty &#8216;man in the middle&#8221; attack.</li>
<li>Finally it gives your site that touch of class&#8230;. which of course a classy person like yourself relies on.</li>
</ul>
<p>Once you implement SSL certificates on your server you&#8217;ll want to <strong>require secure connections </strong>using Apache&#8217;s rewrite module.</p>
<p><span id="more-266"></span><br />
Now I won&#8217;t dwell on the creation and signing of certificates, its already well documented.  If your just starting out though,heres a few links I recommend;</p>
<ul>
<li><a href="http://www.tc.umn.edu/~brams006/selfsign.html" rel="nofollow" title="Creating and Signing your own SSL Certificate"  target="_blank">Creating self-signed certificates</a> (free, but should only be used internally or for testing, users will; see an &#8216;Untrusted&#8221; warning)</li>
<li><a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=10&amp;url=http%3A%2F%2Fwww.lsu.edu%2Fpki%2FSSL_Certificate_Apache.pdf&amp;ei=Z8FcSbDRGaCY8gTdk7GHDQ&amp;usg=AFQjCNELddGd6jW1_Dv1X-CaocEVa4rV2A&amp;sig2=FQMNaM_RlhngJW3MSYiQzw" rel="nofollow" title="Generating a Certificate Signing Request"  target="_blank">Requesting a CA Signed certificate</a> (not free, but the final certificate is trusted and seamless for users)</li>
</ul>
<p>The second link uses the schools internal CA, you will need to pay a public CA like Entrust or Verisign.</p>
<p><strong>All of this information is aimed at &#8216;nix or solaris servers running apache</strong>. Why? cause a production windows server is laughable :-p</p>
<h2>Now that you have a certificate, whats next?</h2>
<p>So there you are you have a shiny new Certificate and Server key, how do you force visitors to your apache driven site to use the SSL?</p>
<p>You copied the certificates into the appropite locations right?</p>
<p>And you have made the needed changes in httpd.conf right?</p>
<p>So now when you view https://example.com you see a &#8216;trusted&#8217; warning or your site right?</p>
<p>If No to any of these than<a href="http://www.sitepoint.com/article/securing-apache-2-server-ssl/" rel="nofollow" title="Securing Apcche Server with SSL"  target="_blank"> this article</a> does a pretty good job of outlining those steps.</p>
<h2>The SSL Works, How do I force connections to use it?</h2>
<p>First you need to decide if you want to force every page on your site to use SSL, or only a particular sub-domain, or maybe just your admin directory.  Since the overhead is minimal there is no harm is forcing the entire domain to leverage SSL, but if it is a self-signed certificate for your personal use than you&#8217;ll most certainly want to restrict its use to your own areas. This prevents users from seeing that nasty warning &#8220;This server is not trusted&#8221;</p>
<p>You&#8217;ll know if your using SSL because the url prefix changes from http to https (s for secure).</p>
<h3>Forcing entire domain to use SSL</h3>
<p><strong>You want any visit, any where to use ssl</strong>. This probably the simplest solution.</p>
<p>Create or append to your htaccess file in the top directory of your server. Some people use a port check (80 is typically http, while 443 is https) but if you have alernate configs or the user just adds :8080 to the end of the url this method is useless.</p>
<p>Instead check whether the https environmental variable is set, if not then redirect.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteCond</span> %{HTTPS} !=<span style="color: #0000ff;">on</span>
<span style="color: #00007f;">RewriteRule</span> ^(.*)$ https://%{SERVER_NAME}$1 [R,L]</pre></div></div>

<h3>Forcing sub-domains to use SSL</h3>
<p>Maybe <strong>you only want mysecretarea.example.com to use SSL</strong>, that&#8217;s easy enough.</p>
<p>Its the same premise as above, but you move the htaccess file into the directory that corresponds to the subdomain. Also change the second line like below;</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteCond</span> %{HTTPS} !=<span style="color: #0000ff;">on</span>
<span style="color: #00007f;">RewriteRule</span> ^(.*)$ https://mysecretarea.%{SERVER_NAME}$1 [R,L]</pre></div></div>

<h3>Forcing a directory to use SSL</h3>
<p>This method cn get a little hairier if your using aliases or redirects on top of this one. You&#8217;ll need to consider what order the commands are read. The basic principle is like so.  <strong>You want all visits to example.com/admin to use ssl.</strong></p>
<p>Create a htaccess file in the parent directory.  Again will check for the https variable, but this time we also check for the sub-directory to be in the path.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteCond</span> %{HTTPS} !=<span style="color: #0000ff;">on</span>
<span style="color: #00007f;">RewriteRule</span> ^/admin/(.*)$ https://%{SERVER_NAME}/admin/$1 [R,L]</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://edwardawebb.com/web-development/forcing-visits-ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirecting users to a Site-Down message</title>
		<link>http://edwardawebb.com/web-development/redirecting-users-sitedown-message</link>
		<comments>http://edwardawebb.com/web-development/redirecting-users-sitedown-message#comments</comments>
		<pubDate>Wed, 29 Oct 2008 22:58:11 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://edwardawebb.com/?p=218</guid>
		<description><![CDATA[When making changes to your backend or user interface, it is nice to let users know just what is going on. Changing out your index page will only work for users who go to your main pages. In order to effectively block all pages, and redirect to a proper message, I recommend using apache&#8217;s .htaccess. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>When making changes to your backend or user interface, it is nice to let users know just what is going on.</strong></p>
<p>Changing out your index page will only work for users who go to your main pages.</p>
<p>In order to effectively block all pages, and redirect to a proper message, I recommend using apache&#8217;s .htaccess.</p>
<p>The best part about this feature is you can <strong>still allow your development team to access the site while blocking everyone else.</strong></p>
<p><span id="more-218"></span></p>
<h3>There are two main pieces to this method;</h3>
<ol>
<li>Create a pretty, funny or informational page explaining why users can&#8217;t reach the good stuff.</li>
<li>Create an .htaccess file to point all request (except yours) to the page above.</li>
</ol>
<h3>The site down message</h3>
<p>A simple &#8216;This site is down for maintenance&#8221; works, but how boring!  Instead you&#8217;ll see a lot of sites using humor to mask the horrible technical struggle that may be taking place behind the scenes.  Elaborate messages like &#8220;Unfortunately our intern, Scott, decided that CAT 5e cables are overrated. However he soon discovered that telepathy is not a common trait among servers.  Please be patient as we work to restore service.&#8221; may or may not hit your target audience. But whatever the case try to be unique in the way that your users have come to rely on.</p>
<h5>sitedown.html</h5>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Baby come back<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>This site is down<span style="color: #339933;">,</span> but no need <span style="color: #b1b100;">for</span> alarm<span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>
You were right<span style="color: #339933;">,</span> it wasn<span style="color: #0000ff;">'t you.. it was us.&lt;/p&gt;
&lt;p&gt;But we'</span>re different know<span style="color: #339933;">,</span> and we really <span style="color: #339933;">&lt;</span>em<span style="color: #339933;">&gt;</span>want<span style="color: #339933;">&lt;/</span>em<span style="color: #339933;">&gt;</span> to change<span style="color: #339933;">.&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Give us another chance<span style="color: #339933;">,</span> and by tomorrow we<span style="color: #0000ff;">'ll be a whole new site, a better site, promise.&lt;/p&gt;
'</span><span style="color: #339933;">&lt;</span>h4<span style="color: #339933;">&gt;</span>Service should be restored by the <span style="color: #990000;">end</span> of October 29th<span style="color: #339933;">&lt;/</span>h4<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>We apologize <span style="color: #b1b100;">for</span> any inconveniences caused<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<h3>The redirect</h3>
<p>Once you&#8217;ve created your page, whatever it may say, save it to the root directory of your site.</p>
<p>The .htaccess is a file read by apache when a directory is accessed.  For redirection it requires that mod_rewrite is enabled in apache.  There is already much good information on general practice and such for <a href="http://httpd.apache.org/docs/1.3/howto/htaccess.html" rel="nofollow" >.htaccess</a>, so we&#8217;ll keep it simple here.</p>
<p><strong>Basically we&#8217;ll use some regular expressions to apply  rules to all incoming requests.</strong></p>
<ol>
<li>IF  the request is not from an internal IP address</li>
<li>AND it is not for our sitedown page (that would cause an infinite redirect loop, oh my!)</li>
<li>THEN send them to the site down page instead.</li>
</ol>
<h5>in /.htaccess</h5>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">RewriteEngine On
RewriteBase /
RewriteCond %<span style="">&#123;</span>REMOTE_ADDR<span style="">&#125;</span> !^<span style="">10</span>\.103\.18\.104     # &lt;--YOUR IP HERE
RewriteCond %<span style="">&#123;</span>REQUEST_URI<span style="">&#125;</span> !^/sitedown\.html$                      
RewriteRule ^<span style="">&#40;</span>.*<span style="">&#41;</span>$ http://example.com/sitedown.html <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>R<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">503<span style="">&#93;</span></span></span></pre></div></div>

<p>The piece [R=503] is the type of header sent to the requester, and used by search engines and other bots. <strong>You should not use 404 or other 400 level errors</strong>.  404 for example means &#8220;this page does not exist&#8221; (and never will).  In reality our page could be valid on any other day. </p>
<p><strong>503 in contrast means &#8220;service (temporarily) unavailable.&#8221; It indicated the redirect to be temporary in nature, as appose to a 301, or 404 meaning permanent.  </strong>This tells Google that your site , and all its pages will be back eventually, and to not purge them from its index.</p>
<p><strong>Another perk of 503 is that dependent services on your site can intelligently relay the message to users.</strong></p>
<h3>That&#8217;s it!</h3>
<p><b>Just restart apache to pick up the changes;</b></p>
<p>/etc/init.d/apache2 restart</p>
<h2>Troubleshooting</h2>
<ol>
<li><strong>Nothing happens!</strong><br />
No worries, check in <strong>httpd.conf</strong> or <strong>default-server.conf </strong>for code that looks similar to whats below AND references your web root directory. In this case it is my /src/www/htdocs directory.<br/></p>
<pre lang="Bash" hl_start="20" hl_count="1">#
# Configure the DocumentRoot
#
<Directory "/srv/www/htdocs">
#
	# Possible values for the Options directive are "None", "All",
	# or any combination of:
	#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
	#
	# Note that "MultiViews" must be named *explicitly* --- "Options All"
	# doesn't give it to you.
	#
	# The Options directive is both complicated and important.  Please see
	# http://httpd.apache.org/docs-2.2/mod/core.html#options
	# for more information.
	Options All
	# AllowOverride controls what directives may be placed in .htaccess files.
	# It can be "All", "None", or any combination of the keywords:
	#   Options FileInfo AuthConfig Limit
	AllowOverride All
	# Controls who can get stuff from this server.
	Order allow,deny

	Allow from all
</Directory>
</pre>
<p>Make sure the AllowOverride is set to All.</li>
<li><strong>Error about infinite loop</strong><br />
Make sure you have a line like the one below, and that it accurately reflects the location of your message page.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">RewriteCond %<span style="">&#123;</span>REQUEST_URI<span style="">&#125;</span> !^/sitedown\.html$</pre></div></div>

<p>Notice the characters
<pre>!, ^, $</pre>
<p>, these are special <a href="http://www.catpumps.com/help/en/regex3.html" rel="nofollow" >metacharacters</a>. <strong>! </strong>means NOT,<strong> ^</strong> is the start just after your domain, and <strong>$</strong> is the end of the url.  So it meets my example of &#8220;http://example.com<strong>/sitedown.html</strong>&#8221;
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://edwardawebb.com/web-development/redirecting-users-sitedown-message/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create Subdomains with Apache &#8211; The Easy Way</title>
		<link>http://edwardawebb.com/apache/create-subdomains-apache-easy</link>
		<comments>http://edwardawebb.com/apache/create-subdomains-apache-easy#comments</comments>
		<pubDate>Fri, 10 Oct 2008 15:04:16 +0000</pubDate>
		<dc:creator>Eddie</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[subdomains]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://edwardawebb.com/?p=153</guid>
		<description><![CDATA[This will walk through the process of adding sub domains to your local server ( onesite.localhost  , twosite.localhost, etc ). To understand this need you are liekly working on multiple sites at once on your local development machine.  So lets say you have an excellent CakePHP application, a gnarly JS sandbox, and your personal start [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This will walk through the process of adding sub domains to your local server ( onesite.localhost  , twosite.localhost, etc ).</strong></p>
<p>To understand this need you are liekly working on multiple sites at once on your local development machine.  So lets say you have an excellent CakePHP application, a gnarly JS sandbox, and your personal start page all belonging to different directories. Problem is, there is only one localhost.  But just like your live server can have subdomains, you can skip DNS and use virtualhosts in Apache do the work. <strong> Imagine, unlimited sub domains all live at one on your localhost pointing to folders all across your machine.</strong></p>
<p><span id="more-153"></span></p>
<p>First off I will be be clear that this is instructions for a Linux device.  If your not running Linux, then <a href="http://download.opensuse.org" rel="nofollow" title="Download the latest SuSE Linux DVD" >start today</a>.  You&#8217;ll be happy you made the switch to the ubiquitous LAMP architecture.</p>
<h4>First thing to do is choose a subdomain for each folder, in my case I have two sub domains;</h4>
<ul>
<li>digbiz.localhost             -   /home/eddie/workspace/Digital_Business/</li>
<li>phpmyadmin.loclahost   -   /srv/www/phpMyAdmin</li>
</ul>
<h4>These are in additions to my usual localhost path;</h4>
<ul>
<li>localhost                      -  /srv/www/htdocs/</li>
</ul>
<h2>Setting your top domain &#8211; localhost</h2>
<p>Most of you have already done this step long ago, but just to be certain, you have set your documentroot and settings in</p>
<h4><strong>/etc/apache2/default-server.conf</strong></h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># Global configuration that will be applicable for all virtual hosts, unless
</span><span style="color: #666666; font-style: italic;"># deleted here, or overriden elswhere.
</span><span style="color: #666666; font-style: italic;"># 
</span>
DocumentRoot <span style="color: #0000ff;">&quot;/srv/www/htdocs&quot;</span>
<span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># Configure the DocumentRoot Properties
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #339933;">&lt;</span>Directory <span style="color: #0000ff;">&quot;/srv/www/htdocs&quot;</span><span style="color: #339933;">&gt;</span> 
	Options All
	<span style="color: #666666; font-style: italic;"># AllowOverride controls what directives may be placed in .htaccess files.
</span>	<span style="color: #666666; font-style: italic;"># It can be &quot;All&quot;, &quot;None&quot;, or any combination of the keywords:
</span>	<span style="color: #666666; font-style: italic;">#   Options FileInfo AuthConfig Limit
</span>	AllowOverride All
	<span style="color: #666666; font-style: italic;"># Controls who can get stuff from this server.
</span>	Order allow<span style="color: #339933;">,</span>deny
	Allow from all
<span style="color: #339933;">&lt;/</span>Directory<span style="color: #339933;">&gt;</span>
<span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># Configure Sub-Domain Properties. This prevents those nasty 403 errors
</span><span style="color: #666666; font-style: italic;">#
</span>
<span style="color: #666666; font-style: italic;"># mysql administration tool
</span><span style="color: #339933;">&lt;</span>Directory <span style="color: #0000ff;">&quot;/srv/www/phpMyAdmin/&quot;</span><span style="color: #339933;">&gt;</span>
	Options Indexes MultiViews
	AllowOverride All
	Order allow<span style="color: #339933;">,</span>deny
	Allow from all
<span style="color: #339933;">&lt;/</span>Directory<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># a client web site built with CakePHP
</span><span style="color: #339933;">&lt;</span>Directory <span style="color: #0000ff;">&quot;/home/eddie/workspace/Digital_Business/app/webroot/&quot;</span><span style="color: #339933;">&gt;</span>
	Options All
	AllowOverride All
	Order allow<span style="color: #339933;">,</span>deny
	Allow from all
<span style="color: #339933;">&lt;/</span>Directory<span style="color: #339933;">&gt;</span></pre></div></div>

<h2>Setting your sub domain&#8217;s paths</h2>
<p>In order for this to work we&#8217;ll need to be specific about which sub domain points where, easy enough. You&#8217;ll notice I am not using httpd.conf, but rather a configuration file in a sub direcotry that is referenced in the main configuration file. This is the typical setup, and any *.conf file in most of the *.d directoriess should be read. <strong>If the folder vhosts.d does not exist, add this code directly to the end of httpd.conf.</strong></p>
<h4>/etc/apache2/vhosts.d/subdoms.conf</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">NameVirtualHost localhost<span style="color: #339933;">:</span><span style="color: #cc66cc;">80</span>
<span style="color: #666666; font-style: italic;"># the mysql tool's url
</span><span style="color: #339933;">&lt;</span>VirtualHost phpmyadmin<span style="color: #339933;">.</span>localhost<span style="color: #339933;">:</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">&gt;</span>
<span style="color: #666666; font-style: italic;"># and absolute path
</span>DocumentRoot <span style="color: #0000ff;">&quot;/srv/www/phpMyAdmin/&quot;</span>
<span style="color: #339933;">&lt;/</span>VirtualHost<span style="color: #339933;">&gt;</span>
<span style="color: #666666; font-style: italic;">#Same for the Client Site
</span><span style="color: #339933;">&lt;</span>VirtualHost digbiz<span style="color: #339933;">.</span>localhost<span style="color: #339933;">:</span><span style="color: #cc66cc;">80</span><span style="color: #339933;">&gt;</span>
DocumentRoot <span style="color: #0000ff;">&quot;/home/eddie/workspace/Digital_Business/app/webroot/&quot;</span>
<span style="color: #339933;">&lt;/</span>VirtualHost<span style="color: #339933;">&gt;</span></pre></div></div>

<p>You may add as many as you want ( to a limit I Imagine) by adding more of the &lt; through&gt; blocks. The very first line of the code should only be used once.  The names you use here are the host names we&#8217;ll need below, so keep note.</p>
<h2>Setting your new sub domains as valid hosts</h2>
<p>For this part you need to edit your you can either edit /etc/hosts directly, or for those who are unsure, use the systems <strong>administration panel &gt; network (services) &gt; host(name)s</strong>.  I&#8217;m running suse so my system panel is Yast, for you it may differ.</p>
<div id="attachment_154" class="wp-caption aligncenter" style="width: 310px"><a href="http://edwardawebb.com/wp-content/uploads/2008/10/mnu.png"><img class="size-medium wp-image-154" title="From the Menu" src="http://edwardawebb.com/wp-content/uploads/2008/10/mnu-300x263.png" alt="mnu 300x263 Create Subdomains with Apache   The Easy Way" width="300" height="263" /></a><p class="wp-caption-text">Begin by launching the Adminstration Panel</p></div>
<div id="attachment_155" class="wp-caption aligncenter" style="width: 310px"><a href="http://edwardawebb.com/wp-content/uploads/2008/10/network.png"><img class="size-medium wp-image-155" title="network" src="http://edwardawebb.com/wp-content/uploads/2008/10/network-300x182.png" alt="network 300x182 Create Subdomains with Apache   The Easy Way" width="300" height="182" /></a><p class="wp-caption-text">Run the Host Configuration module</p></div>
<p>Once your inside the Host configuration module (or hosts file) just add a new record for every sub domain. In my example I use ::1 as the IP address only because IPv6 is enabled on my server. You may need to use 127.0.0.1.</p>
<div id="attachment_156" class="wp-caption aligncenter" style="width: 310px"><a href="http://edwardawebb.com/wp-content/uploads/2008/10/adding.png"><img class="size-medium wp-image-156" title="Adding records to hosts file" src="http://edwardawebb.com/wp-content/uploads/2008/10/adding-300x153.png" alt="adding 300x153 Create Subdomains with Apache   The Easy Way" width="300" height="153" /></a><p class="wp-caption-text">Enter each sub domain as a new record</p></div>
<p>If you open that image up you&#8217;ll see I have already added &#8216;digbiz.localhost&#8217; and was in the process of adding &#8216;phpmyadmin.localhosts.&#8217;  Remember, these are the virtual hosts we setup just before.</p>
<h2>Restart Apache</h2>
<p>Once your done adding the sub-domains clcik finish and the settings will be saved. You can now restart apache and test it out.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/init.d/apache2 restart</span></pre></div></div>

<p>Note: I was curious if you could set up completely new domains, mylocalhost. I didn&#8217;t have much luck though. If anyone has a reason, or has in fact succeeded I would love to hear about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://edwardawebb.com/apache/create-subdomains-apache-easy/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

