Had a minor issue today from a client using Open Mind Commerce that took a bit of time to track down and solve but the solution was quite simple so I thought I would share…
Open Mind Commerce uses ISAPI Rewrite to produce search engine sexy (I don’t like the word safe) URLs so www.domain.com/store/d1-my-department/ is rewritten server side so the template actually executes www.domain.com/store.cfm?deptid=1
Now this works great until the client changes the URL structure in their settings which although a great feature for setting the actual URL can lead to duplicate content in the SEs.
I had to find a way to look at the URL before it was rewritten, compare this to the real URL in the database and then redirect if it was different.
This variable supplies you with the raw URL before it is rewritten server side, bonza! So pseudo code time…
<cfif cgi.HTTP_X_REWRITE_URL NEQ "my stored URL">
<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value="http://www.new-url-indatabase.com">
All we are doing here is comparing the incoming rewritten url with the one that should be in use (from our database) and then using the cfheader command to do a 301 redirect. The result? No more dupes…