Posts Tagged ‘modrewrite’

Clean URLs in PHP Yii Framework

Wednesday, November 18th, 2009

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:

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
),

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/mod_rewrite.so

I think that’s about it…


TheWayOfCoding.com

Pages

Article Archives

  • 2011 (8)
  • 2010 (13)
  • 2009 (11)
  • 2008 (23)
  • 2007 (10)
  • 2006 (7)

Popular Article Tags

Most Recent Articles