pretty urls on IIS 7.5 with mod rewrite

Hi everyone,

First of all, I’m new to coldbox, so i surely will often need information about the framework in the near futur. :slight_smile:

I’m working on an old website and i would like to rewrite it and implement coldbox framework but we don’t have time to do it from scratch for now, we will have to do it pieces by pieces.
So first thing i installed coldbox in parallel of the existing legacy code with a basic configuration, created a few handlers, views, etc… and everything seems to work fine.
Now i would like to implement pretty urls. But i’m a bit lost on the IIS mod rewrite configuration and routes definitions.

basically what i want to do:

turn

into

so i edited the applicationhost.config file on the server

added the following

<rule name="Insert index.cfm" stopProcessing="true"> <match url="^fw" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="fw/index.cfm/{PATH_INFO}" appendQueryString="true" /> </rule>

in coldbox.cfc enabled SES interceptor

`

interceptors = [
{class=“coldbox.system.interceptors.SES”}
];

`

but it seems that the cgi.path_info is always empty when i dump cgi scope (but it works when i call the legacy code this way http://www.mywebsite.com/en/index.cfm/hello =>cgi.path_info = /hello)

then i added the following route in routes.cfm

addRoute(pattern="fw/:lg/:handler/:action?");

but i guess it doesn’t work because of the empty path_info

What i’m I missing?

Any help would be appreciated :slight_smile:

Thanks

OMG…

When will people learn that the CGI approach is flawed, this has been discussed so often in every group that I am in, ColdFusion 10 fixed an issue that makes it appear that this is the case. The problem is that the code is wrong.

Now down to your issue.

http://blog.coldbox.org/blog/coldbox-and-url-rewrites-with-iis-7

Explains what you need.

I already saw that blog post, but it didn’t help me. So thanks anyway.

I can’t use the IIS built in rewrite tool to help me on this, i have to do it directly in the applicationhost.config file

the code i added there is based on the one i found on coldbox doc which says to add this

**<rule** name="Insert index.cfm" stopProcessing="true">
                    **<match** url="^(.*)$" ignoreCase="false" />
                    **<conditions** logicalGrouping="MatchAll">
                        **<add** input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        **<add** input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    **</conditions>**
                    **<action** type="Rewrite" url="index.cfm/{PATH_INFO}" appendQueryString="true" />
                **</rule>**

I just modified it a bit to try making it work for the fw/ directory
i guess my problem is just that the {path_info} used in the rewrite action is empty

I don’t have an experience with this method, could you tell me the difference between using ApplicationHost.config and web.config?

As far as I can tell, they syntax for the two is identical, have you downloaded ContentBox and checked the rules in there?

Never mind I Googled it.

From what I can see ApplicationHost.config is a global configuration for IIS mod_rewrite and other IIS settings, that begs the question why you can’t use web.config, or does this have to be a global setting and not a per website setting?

There’s should not be a difference in both methods. Applicationhost is just at server level and web.config is at site level if i’m correct.

I didn’t try contentbox yet.

Then I don’t understand this comment

I can’t use the IIS built in rewrite tool to help me on this, i have to do it directly in the applicationhost.config file

What do you mean by that, if you can’t use mod_rewrite (which by the way is not built in as you have to install it) and have to use ApplicationHost.config?

This doesn’t make sense.

indeed i didnt meant that i could not use mod rewrite but the user interface of it
Sorry for my bad english

can’t use it cause the infrastructure team wants it to be a global setting for some performance concern

Hmmm, I doubt very much there is any perfomance issues at all. But having said that if this is only going to be one application, then you could store it there. Personally, the web.config is there for a reason, why not use it. Make backing up the IIS configuration for a site a lot easier, especially if there is ever a need to restore the application onto a new server. The less you need to remember to do, the easy it becomes.

Ok, besides all that, the syntax is the same no matter what, so with that in mind and you HAVE mod_rewrite for IIS installed then the following should work.

But again, if you have patched ColdFusion and HAVE NOT reset your connectors for ColdFusion to IIS, then you are going to continually have these issues.

<?xml version="1.0" encoding="UTF-8"?>

Ok but i just updated the connectors
=>i’m on a ACF10 with update 11 =>connector isapi_redirect.dll 2013-05-23 shouldn’t it be ok then?
I see that the old connectors are still there in old previous directories, do i have to remove them completely?

The older directories getting called by IIS at all? But yeah I would remove them.

With the version, how are you getting that? If it is by the file itself, from what I can determine is that IIS caches the extensions etc., so if you don’t run the web configuration tool to remove the connector and add the connector again. It will be caching the older ISAPI extension.

If you are using any instances of ColdFusion other than the default installation, make sure you run the web configuration tool from that instance directory.

Updating can only be done by removing them all and re-applying them, you can do this manually, but if you do then please make sure you restart not only IIS but ColdFusion 10 or the instance you are updating. I would recommend doing the web configuration tool method as it does all this for you.

Oh and if you are doing this on a global level in IIS, you WILL need to restart IIS and each website currently running on IIS and active.

Alleluiahhhhhhhh.

Doing it with the wsconfig.exe fixed the issue.

Thanks Andrew and Brad

Hello

We use Helicon Ape, which is 199 Dollars per server. Believe me, the money is invested very good. All the benefits and features of apaches .htaccess are available for ISS hassle free.

Ape plugs into IIS wihout changing anything on the configuration of IIS.

Cheers