-
Notifications
You must be signed in to change notification settings - Fork 117
URL Rewrite Rule Examples
Rewriting is what enables your API URLs to look like this:
http://example.com/api/artists
Instead of like this:
http://example.com/api/index.cfm
This page gives example URL Rewriting rules for the most common Rewriting engines.
See the official documentation for more information.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/api/(.*) /api/index.cfm/$1If you installed Tomcat separately from ColdFusion, you need to make use of endpointUrlParam *or* add Servelet Mappings for each API you create as described here.
The Tomcat flavor installed by the CF installer is unaffected: If that's where you got Tomcat, you can skip this.
If you choose to use endpointUrlParam with the default config, your rewrite rules should look like this:
RewriteCond %{REQUEST_FILENAME} /api/
RewriteCond %{REQUEST_FILENAME} !/api/index.cfm
RewriteCond %{REQUEST_FILENAME} !/api/resources
RewriteRule ^/api/(.*) /api/index.cfm?endpoint=/$1 [PT]where /api/ is the path from your web root to where ever you installed Taffy i.e. it should have a resources/ subfolder. You'll still need the mappings in Application.cfc in that folder to match, of course.
See the official documentation for more information.
RewriteRule ^/api/(.*)$ /\api/index.cfm/$1Note: As far as I can tell, the backslash in the 2nd half of the rule ("\api") SHOULD NOT be necessary, but I've seen more than one report that someone's rule didn't work without it, but did after adding it. I don't understand why it's necessary, but I'm documenting it here for your benefit!
See the official documentation for more information.
?Be awesome: Contribute to the wiki and document what this syntax should be!
See the official documentation for more information.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="api" stopProcessing="true">
<match url="^api/(.*)$" ignoreCase="false" />
<action type="Rewrite" url="api/index.cfm?endpoint=/{R:0}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>