Using mod_rewrite with PHP

Posted on August 24, 2008
Filed Under Apache, PHP |

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);
?>

Comments

Leave a Reply




  • 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.