<?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>Mike Chambers &#187; apache django tip</title>
	<atom:link href="http://www.mikechambers.com/blog/tag/apache-django-tip/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikechambers.com/blog</link>
	<description>code = joy</description>
	<lastBuildDate>Sun, 15 Jan 2012 05:46:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>TIP : How to get Apache Location directive to match trailing slashes</title>
		<link>http://www.mikechambers.com/blog/2008/05/01/tip-how-to-get-apache-location-directive-to-match-trailing-slashes/</link>
		<comments>http://www.mikechambers.com/blog/2008/05/01/tip-how-to-get-apache-location-directive-to-match-trailing-slashes/#comments</comments>
		<pubDate>Thu, 01 May 2008 19:03:24 +0000</pubDate>
		<dc:creator>mikechambers</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[apache django tip]]></category>

		<guid isPermaLink="false">http://www.mikechambers.com/blog/?p=1237</guid>
		<description><![CDATA[I am working on deploying a django app online, and thus need to use the Apache Location directive to point to my django app. This is pretty straight forward: &#60;Location &#34;/foo/&#34;&#62; SetHandler python-program PythonPath &#34;[&#x27;/path/to/djangositedir/&#x27;] + sys.path&#34; PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE settings PythonDebug On &#60;/Location&#62; Note: You will normally add / edit this in the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.mikechambers.com%2Fblog%2F2008%2F05%2F01%2Ftip-how-to-get-apache-location-directive-to-match-trailing-slashes%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif&amp;source=mesh&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I am working on deploying a <a href="http://www.djangoproject.com/">django</a> app online, and thus need to use the <a href="http://httpd.apache.org/docs/1.3/mod/core.html#location">Apache Location directive</a> to point to my django app.</p>
<p>This is pretty straight forward:<br />
<span id="more-1237"></span><br />
<code>
<pre>&lt;Location &quot;/foo/&quot;&gt;
        SetHandler python-program
        PythonPath &quot;[&#x27;/path/to/djangositedir/&#x27;] + sys.path&quot;
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE settings
        PythonDebug On
&lt;/Location&gt;</pre>
<p></code></p>
<p>Note: You will normally add / edit this in the httpd.conf file for your apache installation.</p>
<p>Basically, you just map &#8220;/foo/&#8221; to the python handler. Anytime someone goes to a URL that begins with &#8220;&#8221;/foo/&#8221;" on your site, it will be handled by Python and your django app.</p>
<p>However, if someone leaves of the trailing slash like so &#8220;/foo&#8221; then the location doesnt match and the server will return a 404. </p>
<p>Luckily, this is fairly easy to fix, and I wanted to post it here for future reference. Just use a regular expression to match either &#8220;/foo&#8221; or &#8220;/foo/&#8221;. Here is the updated directive:</p>
<p><code>
<pre>&lt;Location ~ &quot;/foo(/|$)&quot;&gt;
        ...
&lt;/Location&gt;</pre>
<p></code></p>
<p>Note that the &#8220;~&#8221; is important as it enabled regular expression support. Basically, this says match anything that begins with &#8220;/foo&#8221; and either has a trailing &#8220;/&#8221; or ends &#8220;$&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikechambers.com/blog/2008/05/01/tip-how-to-get-apache-location-directive-to-match-trailing-slashes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

