Skip to main content
February 9, 2010
Question

Regex to rewrite urls

  • February 9, 2010
  • 4 replies
  • 732 views

I've been searching all over google and these forums and kind of have an understanding on how to do this, but i just can't figure this out with regex. I know there is a way to rewrite urls using mod_rewrite to make coldfusion urls seo friendly but it just doesn't work for me lol....

This is the url i currently have:

domain.com?type=soccer&zip=33141

I'm trying to get it to be

domain.com/soccer/33141

And then also have all the links within the page be re-written as well so when the spiders look at it, all the links look like:

domain.com/soccer/33141 or domain.com/basketball/33139

    This topic has been closed for replies.

    4 replies

    February 11, 2010

    Thank you all for your help, that wax exaclty what i was looking for.

    Inspiring
    February 11, 2010

    You can use regular expressions \&(.)*= and \?(.)*= as shown below:

    <cfset myURL = "domain.com?type=soccer&zip=33141" />

    <cfset myURL = "#REReplaceNoCase('#myURL#','\&(.)*=','/')#" />

    <cfset myURL = "#REReplaceNoCase('#myURL#','\?(.)*=','/')#" />

    <p><cfoutput>#myURL#</cfoutput></p>

    existdissolve
    Inspiring
    February 10, 2010

    Have you looked into the Ionics Isapi Rewrite Filter?  It's free and pretty simple to use.  Of course, you need to have acess to your server in order to use it...but other than that, I've had nice luck with it.

    Inspiring
    February 9, 2010

    You might have better luck with this question on an Apache specific forum, if Apache is your web server.  AFAIK ColdFusion does not handle URL re-writing; this is handled by the web server (Apache or IIS).