Running CodeIgniter on a Windows server

One of the web design projects I’ve been working on the last month and just finished within the last week is an online ticketing demo site, www.mattdailey.net/ticketingdemo/. I created the site as a way to better familiarize myself with the PHP framework, CodeIgniter. It’s a great MVC (Model-View-Controller) framework. Simple, straight-forward, and well-documented. I can see why it’s so popular. Although the learning curve was high for me at first since I never used a MVC framework before. It got very frustrating at times, but I plowed on and had a fully functioning website on my hands.  Until I encountered one last major problem.

CodeIgniter by default inserts ‘index.php’ as part of its URLs, for example ‘http://www.site.com/index.php/example/article’, but there’s a way to remove the ‘index.php’ and make the URL cleaner. It basically involves inserting a .htaccess file in the CodeIgniter main folder and changing the value for $config[‘index_page’] in the config.php file to blank. The .htaccess file redirects the page URLs.

I checked to see if the site was working right after I finished uploading it. The main page came up but none of the links worked. Now I put the demo site on a Windows IIS 7 server hosted by GoDaddy. After narrowing down the problem, I realized the Windows server was not recognizing the .htaccess file. It was a problem I had to do some digging with a solution not readily available. I think this is because PHP developers usually use Apache servers and avoid Windows servers. My reason behind choosing a Windows server was so I could run PHP and .NET if I wanted to in the future.

I came upon a post in the CodgeIgniter forums that contained the solution to my problem. Windows servers use something equivalent to a .htaccess file, called a web.config file. This helpful forum post provided the code to include in a web.config file to get CodeIgniter to work on a Windows server. I followed the instructions in the post exactly and sure enough all of the page URLs worked.

Given I had a hard time trying to find a solution to my problem, I’m hoping this blog post will make it a little easier for those CodeIgniter users who encounter a similar problem hosting their site on a Windows server.

Matthew Dailey

Web developer, photographer, and Photoshop user.