Skip to content

Instantly share code, notes, and snippets.

@imthepitts
Last active December 23, 2015 08:59
Show Gist options
  • Save imthepitts/6610996 to your computer and use it in GitHub Desktop.
Save imthepitts/6610996 to your computer and use it in GitHub Desktop.
IIS URL Rewrite test case. web.config placed in web root, info.cfm placed in /asdf directory. Outbound rules disabled in URL Rewrite. Simple example of rewriting via CF in onRequestEnd.
<cfcomponent>
<cffunction name="onRequestEnd">
<!--- Get the generated output --->
<cfset var output = getPageContext().getCFOutput().getBuffer().toString()>
<!--- Apply outbound link rules --->
<cfset output = reReplace(output, '/info\.cfm\?subjectid=([^=&amp;]+)', '/info/\1', 'all')>
<!--- Clear the previous output and send the rewritten output in its place --->
<cfcontent reset="true">
<cfoutput>#output#</cfoutput>
</cffunction>
</cfcomponent>
hello world
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<a href="/asdf/info.cfm?subjectid=1&nameid=1">asfd</a><br>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="JWildCardHandler" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\1\jrun_iis6_wildcard.dll" resourceType="Unspecified" requireAccess="None" />
<add name="hbmxmlHandler" path="*.hbmxml" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\jrun_iis6.dll" resourceType="Either" responseBufferLimit="0" />
<add name="cfswfHandler" path="*.cfswf" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\jrun_iis6.dll" resourceType="Either" responseBufferLimit="0" />
<add name="cfrHandler" path="*.cfr" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\jrun_iis6.dll" resourceType="Either" responseBufferLimit="0" />
<add name="cfcHandler" path="*.cfc" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\jrun_iis6.dll" resourceType="Either" responseBufferLimit="0" />
<add name="cfmlHandler" path="*.cfml" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\jrun_iis6.dll" resourceType="Either" responseBufferLimit="0" />
<add name="cfmHandler" path="*.cfm" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\jrun_iis6.dll" resourceType="Either" responseBufferLimit="0" />
<add name="jwsHandler" path="*.jws" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\jrun_iis6.dll" resourceType="Either" responseBufferLimit="0" />
<add name="jspHandler" path="*.jsp" verb="*" modules="IsapiModule" scriptProcessor="C:\JRun4\lib\wsconfig\jrun_iis6.dll" resourceType="Either" responseBufferLimit="0" />
</handlers>
<defaultDocument>
<files>
<add value="index.cfm" />
</files>
</defaultDocument>
<staticContent>
<mimeMap fileExtension=".air" mimeType="application/vnd.adobe.air-application-installer-package zip" />
</staticContent>
<!-- Rewrite Rules -->
<rewrite>
<rules>
<rule name="Rewrite Info" enabled="true" stopProcessing="false">
<match url="^(.*)/info/([^/]+)/([^/]+)/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}/info.cfm?subjectid={R:2}&amp;nameid={R:3}" appendQueryString="true" />
</rule>
</rules>
<outboundRules>
<rule name="Rewrite Info Page" preCondition="IsHTML" enabled="false" stopProcessing="false">
<match filterByTags="A" pattern="^(.*)/info\.cfm\?subjectid=([^=&amp;]+)&amp;(?:amp;)?nameid=([^=&amp;]+)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="Rewrite" value="{R:1}/info/{R:2}/{R:3}" />
</rule>
<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<!-- Turn off gzip compression-->
<urlCompression doStaticCompression="true" doDynamicCompression="false"/>
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment