<?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>deny &#8211; Avian Bone Syndrome</title>
	<atom:link href="https://www.avianbonesyndrome.com/tag/deny/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.avianbonesyndrome.com</link>
	<description>An exercise in futility by Daniele Nicolucci</description>
	<lastBuildDate>Thu, 16 Sep 2010 15:59:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.avianbonesyndrome.com/wp-content/uploads/2015/04/cropped-cover-sito-32x32.jpg</url>
	<title>deny &#8211; Avian Bone Syndrome</title>
	<link>https://www.avianbonesyndrome.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">12285558</site>	<item>
		<title>Prettifying URLs with fake subdirectories using mod_rewrite</title>
		<link>https://www.avianbonesyndrome.com/2010/09/16/prettifying-urls-with-fake-subdirectories-using-mod_rewrite/</link>
		
		<dc:creator><![CDATA[Daniele Nicolucci]]></dc:creator>
		<pubDate>Thu, 16 Sep 2010 15:59:56 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[deny]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[jbfw]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[subdirectories]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wtf]]></category>
		<guid isPermaLink="false">http://www.avianbonesyndrome.com/?p=391</guid>

					<description><![CDATA[Lately, I have been trying to define a common basis for most of my web projects, since I often end up reinventing the wheel every time. I have tried a few PHP frameworks, but none of them tickled my fancy, but I have complicated tastes. I am known for reimplementing something from scratch rather than wasting time adapting other people&#8217;s code to my needs, and it&#8217;s often much faster too. Therefore I have been working on JBFW, my very own PHP/Javascript framework. One of the key components of it is pretty URLS and a centralized index.php to handle most of the things. If you access http://mysite.com/news?lang=en, the server will transparently route that to http://mysite.com/index.php?pagename=news&#38;lang=en. At that point, index.php runs the news module if it&#8217;s present, and then loads the news template (possibly showing the result of what was done in the module, if it was called at all.) I find that&#8230;]]></description>
										<content:encoded><![CDATA[<p>Lately, I have been trying to define a common basis for most of my web projects, since I often end up reinventing the wheel every time. I have tried a few PHP frameworks, but none of them tickled my fancy, but I have complicated tastes. I am known for reimplementing something from scratch rather than wasting time adapting other people&#8217;s code to my needs, and it&#8217;s often much faster too.</p>
<p>Therefore I have been working on JBFW, my very own PHP/Javascript framework. One of the key components of it is pretty URLS and a centralized index.php to handle most of the things.</p>
<p>If you access <em><strong>http://mysite.com/news?lang=en</strong></em>, the server will transparently route that to <em><strong>http://mysite.com/index.php?pagename=news&amp;lang=en</strong></em>. At that point, index.php runs the <em>news</em> module if it&#8217;s present, and then loads the <em>news</em> template (possibly showing the result of what was done in the module, if it was called at all.) I find that it&#8217;s a very slick and modular way of handling things, as static pages only need new templates and boom, they are live, with the rest of the framework readily accessible.</p>
<p>The <a href="http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html">mod_rewrite</a> configuration for such a behavior is as follows:</p>
<p><code>RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteRule ^(.*)$ index.php?pagename=$1&amp;%{QUERY_STRING}</code></p>
<p>This means: if the requested filename is not a directory and is not a file, route the request as described (knowing something about <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expressions</a>, or being proficient in creative swearing — which goes hand in hand with regexp — comes in very handy at this point.)</p>
<p>I used a similar, but coarser, approach on my own main website, <a href="http://www.nicolucci.eu">http://www.nicolucci.eu</a>. There, I even used fake subdirectories, so that <a href="http://www.nicolucci.eu/photography/book/glimpses">http://www.nicolucci.eu/photography/book/glimpses</a> will have it show the <em>photography-book-glimpses</em> template. Neat, but doesn&#8217;t work with real subdirectories. It&#8217;s not a big problem on that site, but when you need to have a separate administration section, you need real subdirectories. The problem is that, using the approach I described above, <em><strong>http://mysite.com/admin/login</strong></em> into <em><strong>http://mysite.com/index.php?pagename=admin/login</strong></em>, and while the correct function could be run in PHP by mangling the request as it&#8217;s done for the &#8220;top level&#8221; modules, it could quickly turn into a nightmare.</p>
<p>The solution is to add another set of mod_rewrite rules, as follows:</p>
<p><code>RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteRule ^((.*)/)+(.*)$ /$2/index.php?pagename=$3&amp;%{QUERY_STRING} [L]</code></p>
<p>Yes, that&#8217;s incredibly messy, and I&#8217;m pretty sure that there is a better way to do it. However it works, and for now I&#8217;m going to concentrate on finishing the website and go back to it later. What this does is: if the request has one or more blocks ending wish a slash (the directory), followed by something else (the file name), it is routed to index.php inside that directory, using the file name as a parameter to <em>pagename</em>, plus the original query string as usual. The <em>[L]</em> at the end tells mod_rewrite: please refrain from doing any other change, this is flaky enough. This ensures that <strong><em>http://mysite.com/admin/login</em></strong> effectively calls <strong><em>http://mysite.com/admin/index.php?pagename=login</em></strong>.</p>
<p>Note that this is another block of RewriteCond and RewriteRule, and goes before the original one. I tried to put them together, since the conditions are the same, but after fifteen minutes of trying all combinations I gave up. I&#8217;m sure I was one attempt away from getting it right.</p>
<p>A very clever thing (ok I&#8217;m kidding, it&#8217;s a side effect I hadn&#8217;t fully realized but I&#8217;m glad it&#8217;s there) is that addresses such as img/logo.png are not rewritten because those files do exist. It would probably make sense to exclude common file extensions, such as image files and javascript, from this kind of mangling; or even better, make it only work when the &#8220;file name&#8221; part does not have a dot in it. I&#8217;ll find a way to do it, at some point.</p>
<p>To finish up, an extra little trick that can come in very handy when you want to make sure that certain files are not downloadable by anybody:</p>
<p><code>&lt;Files ~ "\.sqlite3$"&gt;<br />
Order Allow,Deny<br />
Deny From All<br />
&lt;/Files&gt;</code></p>
<p>Make sure that there are no spaces on either side of the comma in the first line. I was quite frustrated because I kept getting the infamous error 500, and there it was.</p>
<p>I hope this spares someone from wasting as much time as I did with this kind of thing!</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">391</post-id>	</item>
	</channel>
</rss>
