Tuesday, April 21, 2009

Apache Mod_Rewrite & Shortcodes

I'm a big fan of Apache's Mod_Rewrite module. One of its benefits is that it allows me to take quite complex, user and search engine unfriendly URL's and have them mapped to ones which are easier to remember and more search engine friendly.

On a personal project I'm working on currently (I'll write more about it later), I wanted to implement a shortcode system similar to the one used for properties on www.daft.ie where a user simply has to type in a forward slash and a short code after the domain name to view a property, the code being specific to that property. Of course, short codes are also useful for posting URL's to Twitter which will also be a consideration for this particular project.

I decided I would construct my shortcodes from the characters a-k, m, n and p to z and the digits 2 to 9. Characters and digits that are easy to confuse such as 1 and l and 0 and o I discarded. This gives me a pool of 31 characters to construct my 6 character shortcodes from.

Now to map my shortcode to the full URL that displays a particular record from the database I added the following line to my .htaccess file.

RewriteEngine on
RewriteRule ^([^./]+)/?$ /$1.php [L]
RewriteRule ^([a-kmnp-z2-9]{6}).php$ /destination.php?urlparameter=$1 [L]

The first line turns the mod_rewrite module on, the second allows URL's to be reached without specifying the script extension and the third line takes my 6 character shortcode and maps it to the URL which displays the particular record the shortcode represents. This worked fine until I realised that it was also going to catch other URL's on my site with 6 letters after the domain name such as http://www.mydomain.com/search.

I finally figured out a workaround using the following rewrite condition directly before my third rewrite rule above:

RewriteCond %{REQUEST_URI} !^/search.php

Now while this works, it could be a bit of a maintanance issue as I will have to add a rewrite condition for every script I add to my root directory that has a name of 6 letters. I thought about making the shortcodes uppercase to avoid confusion with other scripts but this seems to take from the user-friendliness of the system.

Any regular expression or mod_rewrite gurus out there see a way to write my original third line to distinguish shortcodes from valid script names?

Wednesday, April 15, 2009

Register365 - First Outage of 2009

Well, once again Register365 (now Namesco) were experiencing difficulties again this morning, this time with one of the machines providing MySQL services. This outage basically brought down any site using either sql4.hosting365.ie or sql6.hosting365.ie including 4 of mine.

This was particularly annoying as, as back as far as last September while I was working on the Industry Research & Development Group site, I had alerted them to issues with the connectivity of sql6.hosting365.ie (at that point I was receiving many 'server has gone away' messages and some more involved queries were not executing) and only last Thursday reported to them that their instance of PHPMyAdmin was running like a dog.

While the sites were down, although they described the issue on the Status site and gave an assurance that they were working to remedy the problem, there was, as usual, no indication of a resolution time much less the cause why one of their Linux boxes had fallen over.

Top of my list for procrastonated jobs to get done if I start feeling the recession slowdown and get some breathing room is to move all my sites from Register365..

Wednesday, April 1, 2009

The Cost of Confusing Print & Web Design

I've been trying hard today to explain to a client in non-techy terms why it is less than ideal to have someone who mainly does print design work on the look & feel for their website update.

Now don't get me wrong here, I think the designer does good work in the print medium and actually I quite like their aesthetic but, when asked by my client how we might go about cutting costs for the site update, I mentioned that in our previous dealings, their graphic designer
1. Was not providing me with PSD files with each graphic element occupying its own well labeled layer for easy slicing and dicing so I was forced to spend time basically digging out graphical elements I needed to implement the design in XHTML.
2. Was causing extra (and otherwise unnecessary) work for me because they had not taken either standard screen size or the size of interface elements such as form controls into account when producing previous designs.
3. Had obviously no eye for adding elements of design that could be rendered via CSS rather than by using graphics thus making the design much less flexible and reusable not to mention a heavier download.
4, Had produced designs in the past with features that were awkward and time consuming to implement in XHTML
and that all these factors were contributing to cost - though, to be fair, probably not as much as the constant revisions of the copy the client made themselves during the last site build.

There are also indirect cost implications in deploying a site that carries usability issues

These are difficult points to communicate to those outside the web design and development fields and I remain unconvinced that I got them across.

Setting Up a Linux NAS in a Vista Workgroup - Things Worth Remembering

Why is a freelance web developer setting up a NAS in the course of his work you might ask? Well, basically because I am freelance and my SME clients frequently mistake me for their goto I.T. tech support, sys admin, and spiritual guide when I build a site for them.

Anyway, I have just completed the setup of a QNAP TS-209 Pro II for a client which is a great piece of kit, featuring a file server with user authentication accessible via the local network and the Web, a print server, media server, web server, frp server, backup location, MySQL server etc and which also happens to run Python so is pretty much potentially infinitely expandable in functionality.

The QNAP setup itself was a snap but remembering the following points when integrating it into a Vista based workgroup will definitely save some time and headscratching.

1. Set the workgroup name in the network settings for the NAS.

2. Set up your users on the NAS with exactly the same credentials as they use to login to their Vista machines. Vista has a nasty habit of not remembering credentials otherwise even when you click the 'remember password' checkbox when you first log on.

3. If you need to clear Vista's cache of network credentials at any time use the command:

rundll32.exe keymgr.dll, KRShowKeyMgr

If you use the offline files facility with Vista and login to the mapped drive fails, Vista won't always tell you so you may find that the Vista user doesn't see updates to files on the shared server with no obvious reason as the login failure isn't reported and no opportunity is offered to update the credentials. When you run the above command you are presented with a list of cached credentials for your various network accesable servers and you can remove the ones you want to reset.

3. Use the IP of your NAS rather than the server's name when you map drives from it to your Vista machines. Netowrk discovery in Vista is a nice feature but it can be sloooooowwwww.

4. If you're using your NAS as a print server make sure that the printer drivers are up to date on all client machines.

5. Finally, specifically for the QNAP models, the support forums are an invaluable resource with such diverse topics as getting the optimum disk spin-down control to running a VPN server (yes, I know, not the greatest idea in terms of network topography but some might want to do it) on your QNAP.

Happy networking!