Movie Gazette Technical Brief

Making Dynamic URLs Static

or how to have a database driven site with no query strings appearing in the urls

The method used on this site relies on an asp custom 404 error page (it needs to be set as a URL, not a file). I first heard of this technique at 4 Guys From Rolla in an article describing how it was used to manage redirects of about 6000 pages when the msdn.microsoft.com site was restructured. I have also drawn on other sources so I claim no credit for any originality on my part!

The error handler first analyses the url request and only then executes the necessary database query. The important snippet of asp code looks something like this:-

' step one grab the identity of the page from the query sent to the 404 page:-
strOrigURL = lcase(request.servervariables("QUERY_STRING") )

' step two check if it meets your criteria or is a genuine 404, in my case, I just wanted to check that the page requested belonged to a particular directory and had a numeric name.

if instr(strOrigURL,"/cinereviews/") >0 then

' step three - collect the numeric id requested

intStart = instr(strOrigURL,"/cinereviews/") + 13
intReview = replace(mid(strOrigURL,intStart),"/","")

' step 4 go fetch the record from the database in the usual way

mySQL = "select * from Reviews where id=" & intReview %>
This technique can be used to build whole sites, power a CMS or just serve pages within one directory.

Do test thoroughly that the page when served returns a 200 ok code to the browser since search engines will choke on 304 or 404 codes. It should do, but it is worth checking.

Your page usage stats will probably be confused by this technique so it is worth setting up an additional script to analyse details of the requests for your custom 404 page.

You can adapt this technique so that it uses a proper name for pages instead of the numeric ID which I use. In my case I was concerned to ensure that the page names were always unique and the obvious field in my database (the Movie Title) did not, on its own, ensure that this would always be the case. There are benefits in having a meaningful url since some search engines use the url in their ranking algorithm.

The detail of what you will need to add to your code will vary according to your application, but I hope I have described the principle adequately. Good luck and let me know if you need more information.

Tim Marchant

Anti Leaching Script

See also my Anti-leaching Script

I use this to prevent bloggers and forum users ripping off my bandwidth by displaying Movie Gazette images in their posts.

In just one instance, a forum was using one of my images 700 times a day. This one guy was screwing me for 700 x 10Kb = 7MB of bandwidth per day. If they linked back to me then I would be thrilled to bits, but they never bother. Whilst it is flattering that people like my images enough that they want to use them (and they are copyright of the studios anyway) it was getting out of hand. This script put a stop to it.
Reviews


  • www
    MG
 
Welcome visitor from The United States  (IP Address: 38.103.63.61)
New Reviews
Michael Clayton
My Super Ex-Girlfriend
Dogma
The Bourne Ultimatum
3:10 to Yuma
Harry Potter and the Order of the Phoenix
Superman Returns
1408
Arrested Development
Boston Legal
Heroes
Silent Hill
She's the Man
Inside Man
Material Girls
Little Miss Sunshine
Barnyard
Accepted
The Cat Returns
Airplane!
If you can see this, your browser does not support current web standards (Cascading Style Sheets). This site (and many others) will look better if you upgrade your browser.
Netflix, Inc.