Enabling mod_rewrite in Apache 2

Posted on August 24, 2008
Filed Under Apache, PHP, Windows | Leave a Comment

Enable the mod_rewrite module by uncommenting it from the httpd.conf file.

1
LoadModule rewrite_module modules/mod_rewrite.so

Enable .htaccess configurations by setting AllowOverride to All for the DocumentRoot directory.

1
2
3
4
5
6
7
8
9
10
11
12
<Directory "C:/www">
    Options Indexes FollowSymLinks
 
    # AllowOverride controls what directives may be placed 
    # in .htaccess files. It can be "All", "None", or any 
    # combination of the keywords: 
    # Options FileInfo AuthConfig Limit
    AllowOverride All
 
    Order allow,deny
    Allow from all
</Directory>

Using mod_rewrite with PHP

Posted on August 24, 2008
Filed Under Apache, PHP | Leave a Comment

I used apache mod_rewrite to create user friendly and search engine optimized urls for sri-lankan.net. Here is how I did it.

Using the following .htaccess configuration, I redirected all the requests to index.php.

1
2
3
4
5
6
7
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

And decide what to show the user by checking $_SERVER[’REQUEST_URI’]…

1
2
3
4
<?
$url = $_SERVER['REQUEST_URI'];
$parts = explode('/', $url);
?>
  • About

    This is an area on your website where you can add text. This will serve as an informative location on your website, where you can talk about your site.