Search Engine friendly URL in IIS
Posted by: RoninKrysSo SEO (Search Engine Optimized) URLs are all the rage these days and there are some who swear by the method and come to find out that I needed to setup URLs (for a different reason) so that the sub-directories could be used as variables.
So the goal was to take...
http://www.website.com/index.cfm?var=val
and turn it into...
http://www.website.com/val
For my purposes, the name of the variable isn't necessary because the placement in the URL would be planned out, but it could just as easily be (http://www.website.com/var/val/)
Notice that I didn't include the "index.cfm" page in there. This should throw a 404....This DOES throw a 404 in IIS.
I have been told the Apache server has a little voodoo called mod-rewrite that mystically allows the admin to reformat the URL so that the variables are parsed from the string. We are going to do something like that but first we have to get rid of that nasty 404
Custom 404
What you want to do is have the 404 error call on a custom page. In that custom page you can parse out the URL and snag the variables from the URL.First though, lets configure IIS...
As the image above depicts, you want to get into your internet information services program, right-click on your website, select [properties], select the [custom errors] tab, and scroll down to the 404 error. Double click on that....

It will default to message type "FILE" however you can drop down and select "URL".
You then want to put in the name of the page that will process the variables. What ever you named that page on the site you need to put it in as though you referencing it from the root of the site. So if its in the root you might put "/pagename.cfm".
Hit "OK" and close everything down.
Now, regardless of what directory you enter, you will be directed to the processing page.
From here its good to use maybe a Fusebox methodology or some sort of case statement that can evaluate an action or process variable that pull in the code through includes. Beyond that, you can use your own creativity on how you can parse the subdirectories and bring in the code you want to display.
SEO 404??!!
Here, I took the subdirectories extracted them for display.
Hard to believe, but the status code in the page header returned is 200 which is valid so search engines should treat this pretty normal.
As for Stats engines, this actually works better since most stats programs will drop off the variables. There they are kept because they are considered path data. This is great if you need to see very specific data but not so great if you want an overhead view.
So on that note.....
Add URL Query Vars to the end...
Yep, you can tack on Query vars on the end but with a minor caveat, the first (var=val) pair has to be a filler.
So it would look like this...
http://www.website.com/showmembers/?1=1&name=bob
If you use a cfdump to output the URL structure it will look like this
[http://www.website.com/showmembers/?1=] = [1]
[name] = [bob]
Why this is, I don't know, but the first "var/val" pair gets messed up so a filler is needed.
So what good is this? Well, lets say you have one page of code that handles a few slightly different processes. You can specify the process name as the subdirectory (about example would be "showmembers").
Your custom 404 page would figure out the page to include and display and that page would then pull on the URL variables for the specifics.
Then when you go into your stats program you will see hits for "/showmembers/". So the numbers will be grouped by the process name "/showmembers/" NOT the page name, and the URL variables will not be included. Again, this is great if you have a page that might have multiple processes that you want to see hits for in you stats software.
I hope this helps anyone looking for this sort of method with IIS. Would be very curious to see other methods that produce the same results or any suggestions as to how this could work better.
Show extended entry >>