CFWheels: URL Rewriting in a subfolder using IIS
If you check the official documentation on URLRewriting in CFWheels, it’s said that Wheels doesn’t support using URL Rewriting if Wheels is in a subfolder, however there are people out there doing it. I’ve been trying to figure out how to do this by scowering the forums and everything, but just couldn’t find a diffinitive example on how to do it. So as a benefit to myself and others, here’s how to do it under IIS.
Imagine (if you will) we have a website with the following setup:
and we want Wheels to run in the subfolder /myapp/survey. So the full url to our Wheels app would be:
The first step is to right click on your website in IIS and click “properties“.
Then in the ISAPI Filters tab, you are going to install the IsapiRewrite4.dll as a filter. So click “Add” and enter in a name for the filter (call it Rewrite for good measure) and browse to the IsapiRewrite4.dll in your application directory. The path should be (if using this tutorial as a guide):
Click “ok” and then “ok” again. IIS is now setup.
Now it’s time to edit the IsapiRewrite4.ini to reflect the path. Open up the IsapiRewrite4.ini in our application folder, it should look like this:
RewriteRule ^(/.+/.+/.*\?.+\..*)$ /rewrite.cfm/$1
RewriteRule ^(/[^.]*)$ /rewrite.cfm/$1
Now the easy part, edit the rules in the ini file to reflect our application path. Following our example, your IsapiRewrite4.ini should look like this:
RewriteRule ^/myapp/survey(/.+/.+/.*\?.+\..*)$ /myapp/survey/rewrite.cfm/$1
RewriteRule ^/myapp/survey(/[^.]*)$ /myapp/survey/rewrite.cfm/$1
Notice that we added “/myapp/survey” to the beginning of every rule and just before the “/rewrite.cfm” in rules 2 and 3.
Now the only thing left to do is reload our web application in IIS to reflect the changes. If you’re using IIS 6.1 (Windows 2003), this is really easy. Just expand the “Application Pools” folder in the IIS Administrator and find the Application Pool that corresponds to your Wheels application (hint: right click on your website, select “properties”, and click the “Home Directory” tab. The Application Pool that is assign to your website will be list here). Now just right click on the Application Pool and select “Recycle”
That’s it! Now open a browser and point it to:
and you should get the Wheels Congratulations screen. Go luck and leave any comments, corrections or flames below.