<?xml version="1.0" encoding="iso-8859-1"?>
<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:rl='http://www.purl.org/RESTLog/'>
  <channel>
    <title>The Well-Formed Web is now cool.</title>
    <link>http://WellFormedWeb.org/news/24</link>
    <description>
&lt;p&gt;That is to say that all the URLs on this site
are cool, with cool being defined by Tim Berners-Lee in his article 
&lt;a href="http://www.w3.org/Provider/Style/URI.html"&gt;Cool URIs don't change&lt;/a&gt;.
In the article he argues that URLs should never change and the best way
to achieve that is to do some up front design of your URLs so that
you won't need to change them in the future.&lt;/p&gt;

&lt;p&gt;The URLs for the weblog entries on this site used to be 
of the form:&lt;/p&gt;
&lt;pre class="example"&gt;&lt;code&gt;http://WellFormedWeb.org/RESTLog.cgi/1&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; In the article Tim Bernes-Lee gives a list of things to
leave out of your cool URL. Now my URLs were mostly cool because they
didn't include such information as the authors name, the subject,
the status, or the file name extension. The only 
information embedded in that URL is the software mechanism: .cgi.
It has to go. If a new and better
method comes along to server up my content and I 
deploy it then I end up breaking
my URLs, and that's not cool. So I need a way to remove
any reference to .cgi and also allow the old URLs which 
are already linked to out in the wild of the internet
to keep working. The server I am running on requires the use
of the .cgi extension so just renaming the file won't work.&lt;/p&gt;

&lt;h3&gt;Apache to the rescue&lt;/h3&gt;
&lt;p&gt;The Apache module &lt;a href="http://httpd.apache.org/docs/mod/mod_rewrite.html"&gt;mod_rewrite&lt;/a&gt; comes
to the rescue. This powerful module allows rewriting of URLs on the fly. So I have
two ugly URLs to contend with, &lt;code&gt;/RESTLog.cgi&lt;/code&gt; and &lt;code&gt;/stories/RESTLog.cgi&lt;/code&gt;.
The first I want mapped to &lt;code&gt;/news&lt;/code&gt; and the second I want
mapped to &lt;code&gt;/story&lt;/code&gt;. Here is the section of my .htaccess
file that accomplishes that rewriting:
&lt;/p&gt;
&lt;pre class="example"&gt;&lt;code&gt;RewriteEngine on
RewriteBase /
RewriteRule ^news(.*) /RESTLog.cgi$1  [L]
RewriteRule ^story(.*) /stories/RESTLog.cgi$1  [L]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that these rules only modify a URI if they start
with "news" or "story" so the old URIs will still
work even after I switch to using the new URLs. Which
means no broken links. Now that's cool.
&lt;/p&gt;
&lt;p&gt;This change also required some changes on the server side code.
The code was extended by adding a &lt;code&gt;base_uri__&lt;/code&gt; variable
to RESTLogImpl.py that is used as the base URI for
all urls generated. This fixes a problem when accessing
the web site and ModRewrite is in use. SCRIPT_NAME used 
to be used to generate the urls which was easy to do but
if not robust. For example I want all the URLs on
WellFormedWeb to be of the form:&lt;/p&gt;
&lt;pre class="example"&gt;&lt;code&gt;http://WellFormedWeb.org/news/N&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but the server is only configured to execute scripts if the
filename ends in .cgi so I am stuck with:&lt;/p&gt;
&lt;pre class="example"&gt;&lt;code&gt;http://WellFormedWeb.org/RESTLog.cgi/N&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can use ModRewrite to accept &lt;code&gt;/news&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="example"&gt;&lt;code&gt;RewriteEngine on
RewriteBase /cgi-bin/
RewriteRule ^cgi-bin/news(.*) /cgi-bin/RESTLog.cgi$1  [L]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But even with this rewrite in place the SCRIPT_NAME still points to RESTLog.cgi
and the permalinks generated have RESTLog.cgi in them and not news. So the 
answer I came up with is to set it in the main script &lt;code&gt;RESTLog.cgi&lt;/code&gt;. The alternative
was to look for some other potentially missing cgi environment variables
that are present if a rewrite was done, but then I realized that created 
a whole new problem: If I had two installs of pamphlet and they were
configured differently, one for &lt;code&gt;/RESTLog.cgi&lt;/code&gt; and the other for &lt;code&gt;/news&lt;/code&gt;
then posts from each install would have a different form of the permalink. Yuk.
&lt;/p&gt;
&lt;p&gt;Postscript: Much thanks to &lt;a href="http://diveintomark.org"&gt;Mark Pilgrim&lt;/a&gt; for 
sending me some of his .htaccess files as examples and pointing me
to &lt;a href="http://www.engelschall.com/pw/apache/rewriteguide/"&gt;A Users Guide to
URL Rewriting with the Apache Webserver&lt;/a&gt; which is also loaded with examples.&lt;/p&gt;

</description>
    <dc:creator>BitWorking, Inc</dc:creator>
  </channel>
</rss>



