Posts Tagged ‘Annoyances’

Migrating URLs with apache and mod_rewrite

Friday, June 6th, 2008

Having now migrated to Wordpress from my own very customised version of phpBloxsom, which ran the previous incarnation of this blog, Ive been left with the issue of dealing with all the sites pulling my RSS feeds. With the change of software has come a change of url for the location of the feeds.

Apache’s mod_rewrite seems to be the obvious candidate for making this as transparent as possible. In essence what needed to happen was incoming requests for:

"GET /blog/?flav=rss&category=Security HTTP/1.0" and
"GET /blog/?flav=rss HTTP/1.0" respectively need to be converted into:


http://lair.moria.org/blog/archives/category/security/feed

and

http://lair.moria.org/blog/feed respectively

This was achieved matching on the QUERY_STRING variable within apache. The real trick came trying to get the new URLS to appear clean. This proved to be more difficult than I expected. My initial rewrite rules resulted int he following:

"GET /blog/?flav=rss HTTP/1.0" 301 249 "
"GET /blog/feed/?flav=rss HTTP/1.0" 200 54274 ""

The agent was directed to the right url but it still looks ugly. Note the use of a HTTP/301 status code indicating permanently moved rather than a 302 which mod_redirect usually provides. The solution to the appending of the query string turned out to be to force my own null string onto the redirect. The Apache Wiki was where I finally found the right answer. so the way to remove a QUERY_STRING is to append a blank string “?” to the redirect .

The final setup in my .htaccess for Wordpress looks as follows:


RewriteCond %{QUERY_STRING} ^flav=rss$ [NC]
RewriteRule ^$ http://lair.moria.org/blog/feed? [R=301,L]
RewriteCond %{QUERY_STRING} ^flav=rss&(category)=Security$ [NC]
RewriteRule ^$ http://lair.moria.org/blog/archives/category/security/feed? [R=301,L]
RewriteCond %{QUERY_STRING} ^flav=atom$ [NC]
RewriteRule ^$ http://lair.moria.org/blog/feed/atom? [R=301,L]

XP failing to hibernate

Saturday, May 3rd, 2008

The problem

For some time my Laptop and Desktop XP systems have been misbehaving, intermittently when going into hibernate, the desktop much more since it got its upgrade to 4 gigs of Ram. Symptoms include just going blank with heaps of hard disk activity and then just sitting with the HDD light flickering, or stating that there are insufficient resources available — despite heaps of free disk space on the system drive.The other evening I had ad enough and went on a hunt for a potential solution other than the “re-install windows” solution.

This was particularly irritating when the laptop failed to hibernate, and you get home to find a rather warm laptop bag. The other problem being in light of the joyous power cuts we have been experiencing, my UPS software is configured to hibernate on power fail rather than shut down something which wasn’t happening and the UPS batteries were ending up draining. After trying the logical solutions of enable/disable hibernate, defrag the drive, removing the hiberfile.sys, rinse repeat etc. with no tangible effect it was time to look elsewhere.

The solution

The solution was surprisingly simple once I got the right sequence of terms plugged into Google. Microsoft has published a hotfix (Microsoft KB 909095) for exactly this issue. Although billed as:

The computer occasionally does not hibernate and you receive an “Insufficient System Resources Exist to Complete the API” error message in Windows XP with Service Pack 2, in Windows XP Tablet PC Edition 2005, or in Windows XP Media Center Edition 2005

It installs fine on any XP SP2 system, as stated further down in the Microsoft page. With some trepidation I applied to my desktop fully expecting a warning or complaint - none occurred. A reboot later I had hibernate working perfectly again. The cause of the problem is :

To prepare the computer to hibernate, the Windows kernel power manager requires a block of contiguous memory. The size of this contiguous memory is proportional to the number of physical memory regions that the computer is using. A computer that uses lots of RAM is likely to use more physical memory regions when the computer prepares to hibernate. Therefore, a larger amount of contiguous memory is required to prepare the computer to hibernate.

Additionally, the number of physical memory regions varies according to the programs, services, and device drivers that the computer uses. Therefore, the hibernate feature occasionally fails.

What I found interesting is that both systems are up to date, and I’ve never been offered this in any of the Windows update sessions, despite the hotfix being available since August 2006!