Rip's Domain

CFWheels: URL Rewriting in a subfolder using IIS

Posted in CFWheels by rip747 on February 23, 2009

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:

Directory: c:\inetpub\wwwroot\example
Domain: http://www.example.com

and we want Wheels to run in the subfolder /myapp/survey. So the full url to our Wheels app would be:

http://www.example.com/myapp/survey

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):

c:\inetpub\wwwroot\example\myapp\survey\IsapiRewrite4.dll

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 ^(/(flex2gateway|jrunscripts|cfide|cfformgateway|railo-context|files|images|javascripts|miscellaneous|stylesheets).*)$ $1 [L,I]
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(/(flex2gateway|jrunscripts|cfide|cfformgateway|railo-context|files|images|javascripts|miscellaneous|stylesheets).*)$ /myapp/survey/$1 [L,I]
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:

http://www.example.com/myapp/survey

and you should get the Wheels Congratulations screen. Go luck and leave any comments, corrections or flames below.

8 Responses

Subscribe to comments with RSS.

  1. Daniel said, on June 27, 2009 at 9:09 pm

    how can this be done in apache?

  2. rip747 said, on August 25, 2009 at 10:50 am

    you would just have to edit the .htaccess file that comes with cfwheels and put the subfolder path before the rewriterules.

  3. Mike Henke said, on October 22, 2009 at 2:14 pm

    Very nice. Thanks

  4. Mike Henke said, on October 22, 2009 at 2:29 pm

    You missed one spot for images,stylesheets,etc:

    RewriteRule ^/myapp/survey(/(flex2gateway|jrunscripts|cfide|cfformgateway|railo-context|files|images|javascripts|miscellaneous|stylesheets).*)/myapp/survey$ $1 [L,I]

  5. rip747 said, on October 22, 2009 at 2:57 pm

    thanks for catching that mike. updated and fixed.

  6. Mike Henke said, on October 28, 2009 at 8:56 am

    People using .htaccess can accomplish this using:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/myapp/survey/(flex2gateway|jrunscripts|cfide|cfformgateway|railo-context|files|images|javascripts|miscellaneous|stylesheets|rewrite.cfm|index.cfm) [NC]
    RewriteRule ^(.*)$ /myapp/survey/rewrite.cfm/$1

  7. Travis said, on July 19, 2012 at 12:36 pm

    what is the web.config equivalent?

  8. brilang said, on August 3, 2012 at 7:18 pm

    How do you do this for IIS 7 and a web.config file?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: