Clean URLs in PHP Yii Framework

Here is a quick tip to save some trouble. The goal here is to get clean urls like http://localhost/site/test/5 or http://localhost/site/contact without having a query string variable and also not having the filename index.php show up.

My configuration:
EasyPHP (apache/php/mysql combo for windows)
Yii PHP framework

In the Yii main.php configuration file you need:


Inside the ‘components’ array area.

In the primary directory where the index.php file is you need a .htaccess files with this in it:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

If you have problems, check your httpd.conf file for these items:

<directory c:\easyphp\www>

Inside that directory section, make sure the rules don’t disallow the removal of index.php or the other rewrite rules.

Make sure this line is un-commented:

LoadModule rewrite_module modules/

I think that’s about it…

Help Support This Website:

Buying something through these Amazon affiliate links within 24 hours of clicking could help me out at no additional cost to you:
USA, UK, Canada, Germany, Spain, France, and Italy

Direct Donation Links:
Paypal, Buy Me A Coffee, or Ko-Fi

This entry was posted in General and tagged , , , , , , , . Bookmark the permalink.