ColdFusion developers can harness the power of SEO friendly URLs in their applications by utilizing the URL Rewrite module which is built into IIS 7+ (or .htaccess on Linux boxes.)
By Search Engine Friendly, I am referring to a URL that looks something like this – with keywords in the URL.
https://www.bob.com/news/5/goodyear-tires-for-sale/
Let me try to explain the SEO Friendly URLs a little more clearly.
Let’s say you have a domain of bob.com
And you have a folder on the server or a section on your site for NEWS articles at bob.com/news/
All the news articles are stored in the database with unique ID numbers.
For example, you could pull up a specific article by going to bob.com/news/?id=5
With me so far?
OK cool, there’s nothing wrong with that, Google can find it, your audience can find it too. However, it’s not officially “SEO Friendly” keeping the id=5 in the URL.
We can get around that with the help of “URL Rewrite”.
Harness the Power of URL Rewrite to create SEO Friendly URLs
Here’s where it gets a little tricky, but it’s really not difficult to configure.
Our goal is to get the URL to something more SEO Friendly, like this…
Bob.com/news/5/goodyear-tires-for-sale/
As you may have noticed, we still have the ID number of the article “5” in the URL (required), but we also have a “dash delimited” title of the article in the URL, which is optional, but that’s what makes it “SEO Friendly,” right?
The URL Rewrite module will take that SEO Friendly URL and convert it back to something that ColdFusion can understand.
This SEO friendly URL...
https://www.bob.com/news/5/goodyear-tires-for-sale/
becomes...
https://www.bob.com/news/index.cfm?id=5&title=goodyear-tires-for-sale
… so ColdFusion can understand it.
Pretty awesome right? Here’s how you do it.
What this actually does is it creates a new rule in your web.config file that looks like this...
Google and your visitors will see this... https://www.bob.com/news/5/goodyear-tires-for-sale/
IIS will convert that URL, behind the scenes, to this... https://www.bob.com/news/?id=5&title=goodyear-tires-for-sale
...so ColdFusion can understand it and parse it.
All you have to do now is write a query that looks something like this…
ADVICE: Always protect your queries against SQL Injection by using cfqueryparam.
NOTE: If you use a Linux server, you simply need to create a similar rewrite rule in your .htaccess file.
HINT: You can use ColdFusion to replace spaces with dashes (-) in the URL for the title of your article using REGEX.
#ReReplace(query.headline,' ','-','ALL')#
Let me know if that helps.
Certified Senior ColdFusion Developer since 1997