I Made Krisna's Times My Way to Write the Times

31Mar/111

.htaccess URL Rewrite on IIS 7.5

Many web applications distributed with .htaccess file to work properly, especially PHP sites. The problem is coming when the web server that is used cannot read or support the .htaccess operation like url rewrite that is common use of .htaccess files. One of that web server is Microsoft IIS, in this post it will be IIS 7.5.

How to do the .htaccess operation with Microsoft IIS 7.5? There is no way (as i know, please tell me if there is). But there is the equivalent operation with .htaccess file do using web.config on IIS.

First we need the IIS module for importing the .htaccess configuration and convert it to web.config configuration, it's named "URL Rewrite 2.0". The module can be downloaded from Mircosoft IIS official site (http://www.iis.net/download/urlrewrite) choose your windows version x86/x64 or install it automatically using Mircosoft Web Platform Installer.

27May/100

Removing ‘index.php’ from CodeIgniter URL

CodeIgniter is the one of most famous PHP Framework now. But if we're using CodeIgniter, by default the URL will be shown as http://localhost/index.php/welcome. Some people doesn't like this way to accessing a website, the index.php suffix in the URL.

Here is some step that can make us accessing the website using http://localhost/welcome. But we're also still accessing the url ith index.php suffix. Before, i will list my system so if we're using different system it may cause different solution.

  1. Apache 2.2.14
  2. PHP 5.2.12

STEP one : create .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#‘system’ can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn’t true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don’t have mod_rewrite installed, all 404’s
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

STEP two : edit CodeIgniter Configuration

$config['index_page'] = "index.php";

TO

$config['index_page'] = "";

That's all. Go and try that....

Source and References

  1. http://arifn.web.id/blog/2009/02/06/codeigniter-removing-indexphp.html