<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>htaccess on S Anand</title>
    <link>https://www.s-anand.net/blog/tag/htaccess/</link>
    <description>Recent content in htaccess on S Anand</description>
    <generator>Hugo -- 0.156.0</generator>
    <language>en-us</language>
    <lastBuildDate>Sat, 19 Nov 2011 13:58:36 +0000</lastBuildDate>
    <atom:link href="https://www.s-anand.net/blog/tag/htaccess/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Protect static files on Apache with OpenID</title>
      <link>https://www.s-anand.net/blog/protect-static-files-on-apache-with-openid/</link>
      <pubDate>Fri, 18 Nov 2011 23:11:50 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/protect-static-files-on-apache-with-openid/</guid>
      <description>&lt;p&gt;I moved from static HTML pages to web applications and back to static HTML files. There’s a lot to be said for the simplicity and portability of a bunch of files. Static site generators like &lt;a href=&#34;https://github.com/mojombo/jekyll&#34;&gt;Jekyll&lt;/a&gt; are increasingly popular; I’ve built a simple &lt;a href=&#34;https://bitbucket.org/sanand0/utils/src/tip/publish.make&#34;&gt;publisher&lt;/a&gt; that I use extensively.&lt;/p&gt;
&lt;p&gt;Web apps give you something else, though, that are still useful on a static site. Access control. I’ve been resorting to &lt;a href=&#34;http://httpd.apache.org/docs/2.2/programs/htpasswd.html&#34;&gt;htpasswd&lt;/a&gt; to protect static files, and it’s far from optimal. I &lt;strong&gt;don’t&lt;/strong&gt; want to know or manage users’ passwords. I &lt;strong&gt;don’t&lt;/strong&gt; want them to remember a new ID. I just want to allow specific people to log in via their Google Accounts. (OpenID is too &lt;a href=&#34;http://www.gibdon.com/2008/06/openid-is-confusing.html&#34;&gt;confusing&lt;/a&gt;, and most people &lt;a href=&#34;http://blog.stackoverflow.com/2010/04/openid-one-year-later/&#34;&gt;use Google anyway&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;The easiest option would be to use Google &lt;a href=&#34;http://appengine.google.com/&#34;&gt;AppEngine&lt;/a&gt;. But their &lt;a href=&#34;http://code.google.com/appengine/docs/billing.html&#34;&gt;new pricing&lt;/a&gt; worries me. Hosting on EC2 is expensive in the long run. All my hosting is now out of a shared &lt;a href=&#34;http://www.hostgator.com/&#34;&gt;Hostgator&lt;/a&gt; server that offers Apache and PHP.&lt;/p&gt;
&lt;p&gt;So, obviously, I wrote a library protects static files on Apache/PHP using OpenID.&lt;/p&gt;
&lt;h3 id=&#34;download-the-code&#34;&gt;&lt;a href=&#34;https://github.com/sanand0/protectstatic&#34;&gt;Download the code&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Say you want to protect &lt;code&gt;/home/www&lt;/code&gt; which is accessible at &lt;a href=&#34;http://example.com/&#34;&gt;http://example.com/&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Copy &lt;code&gt;.htaccess&lt;/code&gt; and &lt;code&gt;_auth/&lt;/code&gt; under &lt;code&gt;/home/www&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In .htaccess, change &lt;code&gt;RewriteBase&lt;/code&gt; to &lt;code&gt;/&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In &lt;code&gt;_auth/&lt;/code&gt;, copy &lt;code&gt;config.sample.php&lt;/code&gt; into &lt;code&gt;config.php&lt;/code&gt;, and&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;change &lt;code&gt;$AUTH_PATH&lt;/code&gt; to &lt;a href=&#34;http://example.com/&#34;&gt;http://example.com/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;add permitted email IDs to &lt;code&gt;function allow()&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, when you visit &lt;a href=&#34;http://example.com&#34;&gt;http://example.com&lt;/a&gt;, you’ll be taken to Google’s login page. Once you log in, if your email ID is allowed , you’ll be able to see the file.&lt;/p&gt;
&lt;p&gt;Feel free to try, or &lt;a href=&#34;https://github.com/sanand0/protectstatic&#34;&gt;fork the code&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://www.s-anand.net/&#34;&gt;S Anand&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;19 Nov 2011 10:31 am&lt;/em&gt;:
I could. But what I&amp;rsquo;ve learnt is that while the static content on this site has survived 14 years, moving from host to host, the same can&amp;rsquo;t be said of ANY of the apps I&amp;rsquo;ve written to create the site. I&amp;rsquo;ve moved from shell scripts to Perl to Python to node.js&amp;hellip; and something else will come up. I can&amp;rsquo;t maintain this stuff. Fortunately, HTML will stay.
So I&amp;rsquo;m making the content primary. I just have a bunch of static files, and that&amp;rsquo;s the key. This is an OPTIONAL library that sits on the side. Without it, the worst that&amp;rsquo;ll happen is that the content becomes public. But otherwise, all URLs will remain unbroken. That&amp;rsquo;s a big win with this approach.
That&amp;rsquo;s also the reason I rejected AppEngine. For my volume of usage, pricing isn&amp;rsquo;t a serious issue. It&amp;rsquo;s simplicity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://www.reviewgang.com&#34;&gt;Manu&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;19 Nov 2011 5:59 am&lt;/em&gt;:
If you are willing to host it outside, then heroku allows one free instance per project.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://www.s-anand.net/&#34;&gt;S Anand&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;2 Dec 2011 10:09 pm&lt;/em&gt;:
I too will probably stay on WordPress for a while. But recently, I&amp;rsquo;ve been creating quite a few microblogs for various topics, and find that the workflow of Markdown -&amp;gt; Dropbox -&amp;gt; PHP -&amp;gt; HTML far too compelling to ignore. It&amp;rsquo;s worked quite well from an ease of publishing perspective. I&amp;rsquo;m still ironing out few edges. Will publish once I do.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://thejeshgn.com&#34;&gt;Thejesh GN&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;25 Nov 2011 11:56 am&lt;/em&gt;:
I was planning to move to static using &lt;a href=&#34;http://www.blogofile.com/&#34;&gt;http://www.blogofile.com/&lt;/a&gt; (python and variety of templating systems are supported). But I am still betting on wordpress for many things. One day I will probably move to static blog.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;http://chmd.fr&#34;&gt;Christophe-Marie Duquesne&lt;/a&gt;&lt;/strong&gt; &lt;em&gt;22 Dec 2013 12:53 pm&lt;/em&gt;:
Hi,
Your post inspired me to write a lighttpd magnet script that protects content regardless of its nature (static or dynamic). I use it:
&lt;ul&gt;
&lt;li&gt;for protecting my (static) photo gallery and only giving access to people I select&lt;/li&gt;
&lt;li&gt;for protecting my (dynamic) rss reader and only giving access to myself&lt;/li&gt;
&lt;li&gt;for protecting my (dynamic) online file manager and only giving access to my girlfriend and myself.
It is completely pluggable, and it sets the REMOTE_USER server variable so that user-aware applications can use this mechanism to authentify you.
&lt;a href=&#34;https://lighttpd-external-auth.chmd.fr/&#34;&gt;https://lighttpd-external-auth.chmd.fr/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Short URLs</title>
      <link>https://www.s-anand.net/blog/short-urls/</link>
      <pubDate>Sat, 11 Apr 2009 18:59:45 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/short-urls/</guid>
      <description>&lt;p&gt;With &lt;a href=&#34;http://joshua.schachter.org/2009/04/on-url-shorteners.html&#34;&gt;all&lt;/a&gt; &lt;a href=&#34;http://laughingmeme.org/2009/04/03/url-shortening-hinting/&#34;&gt;the&lt;/a&gt; &lt;a href=&#34;http://www.scripting.com/stories/2009/03/07/solvingTheTinyurlCentraliz.html&#34;&gt;discussion&lt;/a&gt; around &lt;a href=&#34;http://en.wikipedia.org/wiki/List_of_URL_redirection_services&#34;&gt;URL shorteners&lt;/a&gt;, &lt;a href=&#34;http://digg.com/tools/diggbar&#34;&gt;Diggbar&lt;/a&gt;, &lt;a href=&#34;http://daringfireball.net/2009/04/how_to_block_the_diggbar&#34;&gt;blocking&lt;/a&gt; &lt;a href=&#34;http://farukat.es/journal/2009/04/225-javascript-diggbar-killer-not-blocker&#34;&gt;it&lt;/a&gt;, and the &lt;a href=&#34;http://revcanonical.appspot.com/&#34;&gt;rev&lt;/a&gt;=&lt;a href=&#34;http://twitter.com/kevinmarks/status/1448424167&#34;&gt;canonical&lt;/a&gt; proposal, I decided to implement a URL shortening service on this blog with the least effort possible. This probably won’t impact you just yet, but when &lt;a href=&#34;http://simonwillison.net/2009/Apr/11/revcanonical/&#34;&gt;tools&lt;/a&gt; become more popular and sophisticated, it would hopefully eliminate the need for &lt;a href=&#34;http://tinyurl.com/&#34;&gt;tinyurl&lt;/a&gt;, &lt;a href=&#34;http://bit.ly/&#34;&gt;bit.ly&lt;/a&gt;, etc.&lt;/p&gt;
&lt;p&gt;Since the blog runs on &lt;a href=&#34;http://wordpress.org/&#34;&gt;WordPress&lt;/a&gt;, every post has an ID. The short URL for any post will simply be &lt;code&gt;http://www.s-anand.net/the_ID&lt;/code&gt;. For example, &lt;code&gt;http://s-anand.net/17&lt;/code&gt; is a link to post on &lt;a href=&#34;https://www.s-anand.net/blog/ubuntu-8-10-on-a-dell-latitude-d420/&#34;&gt;Ubuntu on a Dell Latitude D420&lt;/a&gt;. At 21 characters, it’s roughly the same size as most &lt;a href=&#34;http://dooleyonline.typepad.com/dooley_post/2009/02/comparison-of-url-shorteners.html&#34;&gt;URL shorteners&lt;/a&gt; could make it.&lt;/p&gt;
&lt;p&gt;The code is easy: just one line added to index.php:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;link rev=&amp;quot;canonical&amp;quot; href=&amp;quot;http://s-anand.net/&amp;lt;?php the_ID(); ?&amp;gt;&amp;quot;&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;… and one line in my .htaccess:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;RewriteRule ^([0-9]+)$ blog/?p=$1 [L,R=301,QSA]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Hopefully someone will come up with a WordPress plugin some time soon that does this. Until then, this should work for you.&lt;/p&gt;
</description>
    </item>
    <item>
      <title>Caching pages on Apache</title>
      <link>https://www.s-anand.net/blog/caching-pages-on-apache/</link>
      <pubDate>Thu, 14 Aug 2008 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/caching-pages-on-apache/</guid>
      <description>&lt;p&gt;I don&amp;rsquo;t use any &lt;a href=&#34;http://en.wikipedia.org/wiki/Blog_hosting_service&#34;&gt;blogging software&lt;/a&gt; for my site. I just hand-wired it some years ago. When doing this, one of the &lt;strong&gt;biggest problems was &lt;a href=&#34;http://en.wikipedia.org/wiki/Caching&#34;&gt;caching&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Consider each blog entry page. Each page has the same template, but different content. Both the template and content could be changed. So ideally, blog pages should be served dynamically. That is, every time someone requests the page, I should look up the content, look up the template, and put them together.&lt;/p&gt;
&lt;p&gt;I did that, and within a few days outgrew my &lt;a href=&#34;http://www.hostgator.com/&#34;&gt;hosting service&lt;/a&gt;&amp;rsquo;s CPU usage limit. Running such a program for every page hit is too heavy on the CPU.&lt;/p&gt;
&lt;p&gt;One way around this is to create the pages beforehand and serve it as regular HTML. But every time the template changes, you need to re-generate every single page. I had over 2,500 pages. That would kill the CPU usage if I changed the template often.&lt;/p&gt;
&lt;p&gt;At that point, I did a piece of analysis. &lt;strong&gt;Do I really need to regenerate all 2000 blog entries?&lt;/strong&gt; Wouldn&amp;rsquo;t the &lt;a href=&#34;http://en.wikipedia.org/wiki/80-20_rule&#34;&gt;80-20 rule&lt;/a&gt; apply? The Apache log confirmed that 20% of the URLs were accounting for 76% of the hits. So I&amp;rsquo;d be wasting my time regenerating all the pages every time I changed the template.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.s-anand.net/blog/assets/flickr-hits-per-page_2761682983_o-png.webp&#34; title=&#34;Cumulative Hits Per Page&#34;&gt;&lt;img alt=&#34;Graph: 20% of URLs account for 76% of hits&#34; loading=&#34;lazy&#34; src=&#34;https://www.s-anand.net/blog/assets/flickr-hits-per-page_2761682983_o-png.webp&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So based on this, I decided to dynamically cache the pages. When a page is requested for the first time, I create the page and save it in a cache. The next time, I&amp;rsquo;d just serve it from the cache. If the template changes, I just need to delete the cache. This way, I only generate pages that are requested, and they&amp;rsquo;re only generated once.&lt;/p&gt;
&lt;p&gt;OK, so that&amp;rsquo;s the background. Now let me get to how I did it.&lt;/p&gt;
&lt;p&gt;I wrote a Perl script, &lt;code&gt;blog.pl&lt;/code&gt;, that would generate a page in the &lt;code&gt;html&lt;/code&gt; folder whenever it is called. Next, I changed &lt;a href=&#34;http://httpd.apache.org/&#34;&gt;Apache&lt;/a&gt;&amp;rsquo;s &lt;a href=&#34;http://httpd.apache.org/docs/2.0/howto/htaccess.html&#34;&gt;.htaccess&lt;/a&gt; to run this program &lt;strong&gt;only&lt;/strong&gt; if the page did not exist in the &lt;code&gt;html&lt;/code&gt; folder.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# Redirect to cache first&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;RewriteCond %&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;REQUEST_FILENAME&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt; !-f
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;RewriteRule ^&lt;span class=&#34;o&#34;&gt;([&lt;/span&gt;^/&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;*&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\.&lt;/span&gt;html$       html/&lt;span class=&#34;nv&#34;&gt;$1&lt;/span&gt;.html
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# If not found, run program to create page&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;RewriteCond %&lt;span class=&#34;o&#34;&gt;{&lt;/span&gt;REQUEST_FILENAME&lt;span class=&#34;o&#34;&gt;}&lt;/span&gt; !-f
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;RewriteRule ^html/&lt;span class=&#34;o&#34;&gt;([&lt;/span&gt;^/&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;*&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;se&#34;&gt;\.&lt;/span&gt;html$  blog.pl?t&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;$1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The first block redirects Apache to the cache. The second block checks if the file exists in the cache. If it doesn&amp;rsquo;t, the Apache redirects to the program. The program creates the page in the cache and displays it. Thereafter, Apache will just serve the file from the cache.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;This Apache trick can be used in another way. I keep files organised in different folders to simplify my work. But to visitors of this site, that organisation is irrelevant. So I effectively merge these folders into one. For example, I have a folder called &lt;a href=&#34;https://www.s-anand.net/blog/a/&#34;&gt;a&lt;/a&gt; in which I keep my static content. I also have this piece of code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-apacheconf&#34; data-lang=&#34;apacheconf&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;RewriteCond&lt;/span&gt; %{REQUEST_FILENAME} !-f
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;RewriteRule&lt;/span&gt; ^([^/]+)$   a/$1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If any file is not found in the main folder, just check in the &lt;code&gt;a/&lt;/code&gt; folder. So I can access the file &lt;a href=&#34;https://www.s-anand.net/blog/assets/hindholam.midi&#34;&gt;/a/hindholam.midi&lt;/a&gt; as &amp;lt;/hindholam.midi&amp;gt; as well.&lt;/p&gt;
&lt;p&gt;This can be extended to a series of folders: either as a cascade of caches, or to merge many folders into one.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;!-- wp-comments-start --&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Kannan Ekanath&lt;/strong&gt; &lt;em&gt;17 Aug 2008 7:00 am&lt;/em&gt;:
[http://random-thoughts-and-rambling.blogspot.com/]&lt;/p&gt;
&lt;p&gt;Hi,
I wanted to know a comparison/contrast how setting up blog etc in your own hosted space compares with things like &lt;a href=&#34;http://sites.google.com&#34;&gt;http://sites.google.com&lt;/a&gt;. I have always postponed this buying of a domain in favour of things like sites.google.com. Obviously I understand that the advantages would be you can control the LAF, the content, the organisation etc. But have you got a comparison doc or something on what precisely one would get if he hosts things in his own domain instead of a google/yahoo powered wiki style page?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;S Anand&lt;/strong&gt; &lt;em&gt;17 Aug 2008 1:31 pm&lt;/em&gt;:
@Kannan: Don&amp;rsquo;t have anything offhand, Kannan. But buying a domain would make sense anyway &amp;ndash; you could point your domain to sites.google.com transparently. If you wanted to build your own blogging system for your site, though, I&amp;rsquo;d advise against it. I did it because I started in 1999 and there weren&amp;rsquo;t many blogging systems then. Today, it just doesn&amp;rsquo;t make sense.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Nirupam&lt;/strong&gt; &lt;em&gt;18 Aug 2008 7:43 am&lt;/em&gt;:
Hi
Want to create a site for myself. Should I go for own hosted space or should I start using sites like Geosites etc. I want to deploy web-based applications in my site. Can you please advise?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;S Anand&lt;/strong&gt; &lt;em&gt;19 Aug 2008 11:24 am&lt;/em&gt;:
@Nirupam: If you want to deploy your own applications, you should probably create your own site. Get a free hosting service to start with. I&amp;rsquo;ve used 110mb.com, freestarthost.com and awardspace.com, and found them to be OK.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- wp-comments-end --&gt;
</description>
    </item>
    <item>
      <title>Handling missing pages</title>
      <link>https://www.s-anand.net/blog/handling-missing-pages/</link>
      <pubDate>Mon, 24 Dec 2007 12:00:00 +0000</pubDate>
      <guid>https://www.s-anand.net/blog/handling-missing-pages/</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;If something goes wrong with my site, I like to know of it. My top three problems are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&#34;https://www.s-anand.net/blog/monitoring-site-downtime/&#34;&gt;The site is down&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#start2&#34;&gt;A page is missing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.s-anand.net/blog/javascript-error-logging/&#34;&gt;Javascript isn&amp;rsquo;t working&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This article covers the second topic.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;One thing I&amp;rsquo;m curious about is hits to &lt;a href=&#34;http://alistapart.com/articles/perfect404/&#34;&gt;non-existent pages (404s)&lt;/a&gt; on my site. I usually get 404s because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I renamed the page&lt;/li&gt;
&lt;li&gt;Someone typed a wrong URL&lt;/li&gt;
&lt;li&gt;Someone followed a wrong link&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Find the 404&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The first problem is to know when someone gets a 404. I&amp;rsquo;ve seen sites that tell you to contact the administrator in case of a 404. That&amp;rsquo;s crazy. &lt;strong&gt;The administrator should automatically detect of 404s!&lt;/strong&gt; Almost every web server provides this facility.&lt;/p&gt;
&lt;p&gt;The real issue is attention. I receive 700 404s a day. That&amp;rsquo;s too much to manually inspect. And most of these are not for proper web pages, but for images (for example, almost all my 404s used to be for browsers requesting &lt;a href=&#34;http://en.wikipedia.org/wiki/Favicon.ico&#34;&gt;favicon.ico&lt;/a&gt;) or &lt;a href=&#34;http://www.michaelteper.com/archive/2005/11/02/4276.aspx&#34;&gt;weird MS Office files&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m interested in a small subset of 404 errors. Those that hit a &lt;strong&gt;web page&lt;/strong&gt;, not support files. And those &lt;strong&gt;requested by a human&lt;/strong&gt;, not a search engine or a program.&lt;/p&gt;
&lt;p&gt;A decent way of filtering these is to use Javascript in your 404 page. Javascript is typically executed only by browsers (i.e. humans, not search engines), and only in a web page (not images, etc.) So if you serve Javascript in your 404 page, and it gets executed, it&amp;rsquo;s likely to be a human requesting a web page.&lt;/p&gt;
&lt;p&gt;I have a piece of Javascript in my custom 404 page that looks something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;script&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;new&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;Image&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()).&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;src&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;/log.pl&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&amp;lt;/&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;script&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Every time this code runs, it loads a new image. The source of the image is a Perl script, log.pl. Every time log.pl is accessed, it logs the URL from which it was called. I&amp;rsquo;m reasonably guaranteed that these are web pages a human tried to access.&lt;/p&gt;
&lt;p&gt;The reduction in volume is tremendous. On a typical month, I get ~20,000 404 errors. With the Javascript logging, it&amp;rsquo;s down to around 200 a month, and most of them quite meaningful.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Point to the right page&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Sometimes, the change happens because I changed the URLs. I keep fiddling with the site structure. Someone would have links to an old page that I&amp;rsquo;ve renamed. I may not even know that. Even if I did, they can&amp;rsquo;t be bothered with requests to change the link. So I&amp;rsquo;ve got to handle it.&lt;/p&gt;
&lt;p&gt;The quickest way, I find, is to use &lt;a href=&#34;http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html&#34;&gt;Apache&amp;rsquo;s mod_rewrite&lt;/a&gt;. You can simply redirect the old URL to the new URL. For example, I used to have a link to &lt;code&gt;/calvin.html&lt;/code&gt; which I now point to &lt;code&gt;/calvin/&lt;/code&gt;. That becomes a simple line on my &lt;a href=&#34;http://en.wikipedia.org/wiki/.htaccess&#34;&gt;.htaccess&lt;/a&gt; file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-apacheconf&#34; data-lang=&#34;apacheconf&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;RewriteRule&lt;/span&gt; calvin.html  calvinandhobbes.html
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I don&amp;rsquo;t do this for every site restructuring, though. I just restructure, wait for someone to request a wrong page, and when my 404 error log warns me, I create a line in the .htaccess. It keeps the redirections down to a minimum, and only for those links that are actually visited.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Be flexible with the URL structure&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Sometimes people type in a wrong link. Often, these are unintentional. Here are some common misspellings for my &lt;a href=&#34;https://www.s-anand.net/blog/hindi&#34;&gt;Hindi songs search&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;s-anand.net/hindi/
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;s-anand.net/Hindi
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;s-anand.net/hiundi
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Occasionally, people are exploring the structure of my site:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;s-anand.net/excel
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;s-anand.net/music
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;s-anand.net/hits
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I need to decide what to do with both cases. For the former, sometimes my URL structure is too restrictive. I mean, why should someone have to remember to type &lt;code&gt;/hindi&lt;/code&gt; instead of &lt;code&gt;/Hindi&lt;/code&gt; or &lt;code&gt;/hindi/&lt;/code&gt;? Who cares about case? Who cares about a trailing slash?&lt;/p&gt;
&lt;p&gt;In such cases, I map all the variants to the right URL using mod_rewrite. For example, typing &lt;code&gt;s-anand.net/HiNDi&lt;/code&gt; (with or without caps, with or without a slash at the end) will still take you to the right page.&lt;/p&gt;
&lt;p&gt;As I keep discovering new mis-spellings, I take a call on whether to add it or not. The decision is usually based on volume. If two people make the same spelling mistake in a day, I almost certainly add the variant. Most of the time, it&amp;rsquo;s just typing errors like &lt;code&gt;/hiundi&lt;/code&gt; which isn&amp;rsquo;t repeated oftener than once a month.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Provide search&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To handle the exploratory URLs, and people following wrong links, I&amp;rsquo;ve turned my &lt;strong&gt;custom 404 page into a search engine&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For example, when someone types &lt;code&gt;s-anand.net/excel&lt;/code&gt;, I know they&amp;rsquo;re searching for Excel. So I just do a Google Custom Search within my site for &amp;ldquo;excel&amp;rdquo; &amp;ndash; that is, anything following the URL.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a bit more complex than that, actually. I do a bit of tweaking to the URL, like convert punctuations (underscore, hyphen, full-stop, etc.) to spaces, remove common suffixes (.html, .htm) and ignore numbers. Quite often, it matches something on my site that they&amp;rsquo;re looking for. If not, ideally, I ought to try for various alternatives and subsets of the original search string to figure out a good match. But given that the number of mismatches is down to about one a day, I&amp;rsquo;m fairly comfortable right now.&lt;/p&gt;
&lt;p&gt;What this means, incidentally, is that my site is, by default, a search engine for itself. To search for movie-related stuff on my site, just type &lt;code&gt;s-anand.net/movie&lt;/code&gt; and you get a search of the word &amp;ldquo;movie&amp;rdquo; on my site. (Sort of like on &lt;a href=&#34;http://a9.com/&#34;&gt;a9.com&lt;/a&gt;, where searching for &lt;code&gt;a9.com/keyword&lt;/code&gt; does a search on the keyword.)&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
