Tag Archives: IIS

Custom 404 pages with ColdFusion 8, MacOS X and the difference with IIS

For one of the projects we are working on (news will be revealed very soon) we will need to redirect a clean URL like “http://www.mydomain.com/mybox” to a certain record.

Of course, our first thought was that it is easy to create a custom 404 page, add this to the web server configuration, get the query_string and do some stuff with it. Easy right?

Well, in our findings we see that Apache 2.2.6 gives us a empty query_string, where as IIS on Windows Server 2003 returns a nicely formated query_string in the form of “404;http://www.mydomain.com:80/mybox”. Needles to say, that this posts a challenge since we would need to have the “mybox” part of the URL to make something meaningful with it.

Here are the following steps to make this work on Apache.

1. Create a custom 404 page

Simply create a new ColdFusion page. We called ours “404.cfm” and put it in the web root (or in the root of your host directory). Within the template add a <cfdump var=”#cgi#”> or a #cgi.query_string#.

2. Add this to the httpd-vhosts.conf file

Since we are working with different local hosts we are changing the virtual host directives, this gives you a additional value to have custom 404 error pages for each host. If you don’t need that or simply want to have a general 404 page then edit the httpd.conf file and change or add the line “ErrorDocument 404 /404.cfm” (around line 414 in the httpd.conf file).

For virtual hosts do the same, but simply put this line “ErrorDocument 404 /404.cfm” within the virtualhost directive!

3. Restart Apache and test

Within the terminal restart Apache with “/usr/sbin/apachectl restart”. Now surf to the URL “http://www.mydomain.com/mybox”. Do you land on your custom 404.cfm page? If so, you should see a empty “query_string”. If you get an error instead of your page, make sure that you have done step 1 and 2 correctly.

Ok, once it is working we can now get on with the show. That is, we will need to get the rewrite module working. Without it enable, you will never get the query_string value filed. Good thing is, that Apple included Apache 2.2.6 and already compiled it with the rewrite module. If your installation varies or you try this on another Apache version then make sure you compiled Apache with the rewrite module.

4. Check for the rewrite module

Again go into your httpd.conf file and look for the line “LoadModule rewrite_module libexec/apache2/mod_rewrite.so”. Make sure it is NOT commented (that means, is does not have a “#” in front of it).

You will also need to look for the line “AllowOverride None” (about line 210) and change it to “AllowOverride All”.

Save and close httpd.conf.

5. Create a .htaccess file

This part is the key to all of the above. Create a new file, called “.htaccess” and put it in the directory of your 404.cfm page. within the .htaccess file add the following lines:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /404.cfm?%{REQUEST_URI}

This will make sure that the complete URL string gets passed to your 404 page and thus in the cgi.query_string scope.

6. Restart Apache and test

Within the terminal restart Apache with “/usr/sbin/apachectl restart”. Now surf to the URL “http://www.mydomain.com/mybox”. You should see the “mybox” part now in the query_string.

That’s it. Hope this helps some others as we have spent quite some time figuring this out.

Comments { 62 }

ColdFusion cftree and GZip compression

Web-Developers always try to find a way to speed up the application and especially with the new ColdFusion 8 and all its Ajax functionality, if used in full can weight in at around 500k, we try to do "everything" to get better performances.

That said, we lately investigated the use of Gzip compression on the server. Actually the installation and usage is quite simple and indeed works quite well. Unless…

Unless you want to use cftree as a HTML/Ajax variant. If you try to get your cftree code running you will not see any errors, all you will see is a blank page. Actually, it took us a long time until we figured this out. Thus we changed the configuration of the Gzip to not use it on all templates but only on *.cfm files. Using it with this setting and your cftree code will work again.

Comments { 26 }

Running ColdFusion on IIS and have Apache run on port 80 also

The other day, I was asked by a customer how one is able to run ColdFusion with IIS and Apache on the same machine with both Webserver listening on port 80. Since this customer has downloaded our free Digital Asset Management solution, I knew his question was aimed at the Oracle HTTP Server (Apache 1.3) and that solving this could also help our own website and customers behind a firewall which would not allow traffic on port 7777 (the default port installation by Oracle HTTP).

After some thinking I came to the conclusion that this will only be possible with two IP addresses assigned to your network adapter. Thus first we need to assign the new IP to the network adapter.

If that is done we now have to tell IIS and Apache to only listen to the specified IP address. The big problem with this approach is that IIS has a featured called “Socket Pooling” that claims all ports for all loaded IP addresses, even if not configured in IIS!!!. Actually this has struck me for quite some time and it took quite some searching and reading to find this out. Fortunately there is a way to configure IIS to only listen to the IP we want.

Configure IIS to listen to only one IP address

1. First of all grab yourself the “httpdcfg.exe” utility which is within the .cab file within the support folder of the Windows Server 2003. With the latest releases you will find the folder on CD 2. To make it even easier I make it available here.

2. Now go into the command prompt and stop IIS with “net stop http /y”

3. Now tell IIS to listen to the IP you want with “httpcfg set iplisten -i 192.168.1.100″

4. Make sure that IIS has only your IP configured to listen for with “httpcfg query iplisten”

5. Restart IIS with “net start w3svc” (Changes are done but you might not see them already).

Configure Apache to listen to only one IP address

Next we need to tell Apache to only listen to the other IP address. Fortunately this takes only some small part of configuring.

1. Open up your “httpd.conf” file.
2. Search the line where it says “listen 7777″ (or your port you want to change).
3. Change this to read: Listen 80 Listen 192.168.1.101:80 If you have virtual host containers setup to listen to a IP address you will need to change those values as well, of course.
4. Save.

VERY IMPORTANT: If you have done the above you must restart your machine. Doing otherwise with just restarting IIS and Apache will not reflect the changes correctly. If you see it working we still recommend restarting your server (hey, after all it is Windows :-) )

Voila, after you have restarted your machine you should be able to access both IP’s one being served by IIS and the other by Apache.

This setup has been tested and known to work with Windows Server 2003 and IIS 6.x and Apache 1.3.x. Also this setup would add some security to your database since you could have a public IP address for, as an example, your IIS and have an internal IP address to your Oracle database over Apache. Your requests to the database would then go to the internal IP. Within Coldfusion your data source would then point to the internal IP. This would be a “secure” setup for your web applications which would only allow access to the database trough your web application.

Comments { 39 }

When cfforms don’t work on a CF server

I have had this problem for some time now that on our Windows 2003 Server all validations did not work. Meaning the cfform with input and required=”yes” did not work at all. I have looked around but could not find a solution up to now. It is even a simple one.

If this happens to you too then just do the following steps:

  1. Run Remove_ALL_connectors.bat usually located at C:\CFusionMX7\bin\connectors\ to remove all connectors from all websites.
  2. Run IIS_connector.bat also found in C:\CFusionMX7\bin\connectors\ which will add all connectors to all websites again.

I have done this now and all forms work again. Great.

Comments { 34 }