Reputation: 648
I'm taking over a ColdFusion application and I'm having some trouble with the rewrites.
The site is on an IIS7/CF9.0.1/SQL Server stack. Helicon manager is handling the rewrites.
Most of the URLs are written to an html file, so we'd have something like /profile.html
The URL gets rewritten by this line:
RewriteRule /([^\?]*?)\.(html)(\??)(.*)? /default.cfm?name=$1.$2&$4 [I]
The problem occurs when there's a query string like /view.html?id=123. The query string should be written by the $4 variable, but I'm never getting anything in the application, when I dump the URL like so:
<cfset objRequest = GetPageContext().GetRequest() />
<cfset strUrl = objRequest.GetRequestUrl().Append(
"?" & objRequest.GetQueryString()
).ToString()
/>
<cfoutput>#strUrl#</cfoutput>
I get something like: http://10.211.55.6/default.cfm?name=view.html&. The query string never shows up.
I believe it's an IIS setting - allowing the .html handler access to GET variables maybe? I've set up an .html handler, but no luck.
Upvotes: 0
Views: 390
Reputation: 7066
The reason this does not work is because RewriteRule never sees the query string, only the path of the resource. To access the query string you need to use a Rewrite Condition
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html&%1 [NC,L]
In this example we are just examining the query string and using %1
which means the first group from the RewriteCond
this is overkill in your example where you don't need to match anything so you could do it like this:-
RewriteEngine on
RewriteBase /
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html&%{QUERY_STRING} [NC,L]
However, the smart way is just to use the correct flag to do what you want to do which is QSA
which means query string append like so:-
RewriteEngine on
RewriteBase /
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html [NC,QSA,L]
All the docs for Helicon's ISAPI rewrite can be found here: http://www.helicontech.com/isapi_rewrite/doc/. They're quite handy to bookmark.
I hope that helps.
Upvotes: 3