I'm trying to map a URL like this:
www.domain.com/some-page.cfm?coid=1
to be more user-friendly like this:
www.domain.com/some-page/company-name
or
www.domain.com/company-name
I've tried over and over using URL Rewrite in IIS and can't for the life of me get it to work.
Any help would be appreciated!
I think you may actually want to do the opposite... use IIS to map /abc.htm
requests to /?id=abc
, right? (For the rule you are requesting, I recommend writing that using ColdFusion.)
Here's an IIS rule that we use in order to not expose ".cfm" in our blog URLs. Anything URL parameters after "/blog/" in the URL is available to ColdFusion as URL.WebPath
. Additional URL parameters are retained. If you modify this, I recommend matching a URL patterns (like "blog/" or "/detail-") so that only specified URLs are rewritten.
<rewrite>
<rules>
<rule name="CFMBlog" patternSyntax="ECMAScript" stopProcessing="true">
<match url="blog/(.*.htm)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{SCRIPT_FILENAME}" matchType="IsFile" negate="true" />
<add input="{PATH_INFO}" pattern="^.*(blog/index.cfm/).*$" negate="true" />
</conditions>
<action type="Rewrite" url="/blog/index.cfm?WebPath={R:0}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
On the ColdFusion-side, you'll want to analyze the URL and ensure it's in the proper format. You don't want to have both versions of the URLs responding for fear of SEO duplication (unless you set up URL canonicalization). I'm my experience, it's best to serve a 301 Permanent Redirect to a lowercased, dash-separated ".htm" version of the URL.
In your CFM pages, you'll need to add some logic to check whether .htm
is in path_info
, URL.COID
exists in the original request and URL.webpath
does not. Depending on your situation, you could perform a 301 to redirect to the HTM version of the URL so that both search engines & users are aware of the new URL.
Have you taken a look at this? IIS URL Rewrite not working with query string
Or if you want to do this with pure ColdFusion without IIS, how about this?
some-page.cfm
<!--- Test for query string params --->
<cfif StructKeyExists(url, "coid") and url.coid eq 1>
<cflocation url="/some-page/company-name" addtoken="no">
<cfelse>
<!--- Other processing here... --->
</cfif>