October 15, 2014

October 15, 2014
In this article, we are going to discuss about How to create a SEO and Clean URLs in Yii PHP Framework. Yii is a modern and robust PHP framework aimed to secure and scalable programming. It is not hardern or more complex compared to the popular PHP frameworks such as CakePHP. It supports all major databases from MySQL to Sqlite. The best is that it is much faster and scalable compared to other frameworks. The latter is what made me reconsider using it over CakePHP.

By default Yii routes all URL requests transparently through the main index.php file and your URLs look like this:


Our aim is to make it look:


For this purpose follow these steps:

Open your site root protected/config/main.php and uncomment the part about the urlManager so that it looks like this:

     'showScriptName'=> false,


Add the following lines to your .htaccess (provided you are using Apache or compatible web server):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . index.php

Last you may wish to drop controller / action from the URL. This can be also done by a custom rule in the urlManager array in protected/config/main.php:


This will ensure that by just going to http://example.org/about you will be routed to http://example.org/site/page/view/about.


Post a Comment