Yii 1.1: Url: hide index.php


Maybe it looks simple, but some time ago I need some time to find a solution of this case. I finally got it, and I want to share that I also experienced such cases. So that it can make reference.

Neither let us do the steps:

  • Make sure that the hosting / your pc mod_rewrite module is active. if not actively try to activate in a way, open the httpd.conf file. You can check this in the phpinfo.php to find out.

change this setting :

#LoadModule rewrite_module modules/mod_rewrite.so

to be

LoadModule rewrite_module modules/mod_rewrite.so
  • then go to .htaccess file, and try to modify to be:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

if above does not work try with this:

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

  • move .htaccess file to root directory, where is index.php thare.
 - protected
 - index.php
 - .htaccess
  • Set main.php in your yii configuration, at component :
  • so.., good luck

For reference material I managed to do in my personal website (check my profile).

NB: This for hide index.php

Total 14 comments

#16901 report it
Sukunj Mendpara at 2014/04/10 11:59pm
Nice Article

Very Nice article ..thank you so much this works for me..

#15878 report it
jjokucha at 2013/12/25 03:25pm

by "moving .htaccess to webroot" you mean delete .htaccess within protected folder? if so it's horrible for security cause the protected folder is accessible for anyone. i think you mean copy that .htaccess and use it for this urlManager and keep the other one.

#9725 report it
thiromi at 2012/09/06 06:50pm
One more thing...

Also, if you're on a virtual directory (e.g. using

Alias /dir/ "/dir/"

on your apache configuration) you MUST use a

RewriteBase /dir/

statement on your .htaccess file, other than the rewrite won't work again.

#9233 report it
Mohamed Alsemany at 2012/07/30 08:21pm
That Sounds good

Thanks for this great article

I just tried it but I fail first because I forget and put this variables


inside the array of the rules :)

I just a newbie with YII :) so I'm just confused

Thank you again

#8945 report it
Alf_75 at 2012/07/09 09:21am
Hello, May you take a look on my yii topic

Hello, May you take a look on my yii topic


I have made what is required but it does not work. I dont understand why.

Thank you!

#7842 report it
wangxiantong at 2012/04/22 06:53am
win32 apache config

As thiromi said, make sure that you change the "AllowOverride" flag to "All"

# 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**

#7037 report it
cksaito at 2012/02/20 03:27pm

I am using WAMP, it works after i include the line:


in file [.htaccess]

thanks for article.

#6113 report it
Iza at 2011/12/13 12:53pm

Thank you! It works! :D

#4467 report it
thiromi at 2011/07/11 06:16pm
Not only check mod_rewrite instalation

To get mod_rewrite working not only mod_rewrite must be installed, but also check in the Apache directory config (/etc/apache2/sites-enabled/000-default on Ubuntu installed via apt-get) if the rule "AllowOverride None" exists in your project's directory config. If so, change it to "AllowOverride All". I have spent hours because of this thing, so it's my tip to get things working.

#4424 report it
Hermans at 2011/07/07 04:57am

thank you, you are right. This can not be run if not in the main config settings.

Set main.php in your yii configuration, at component :
#4423 report it
lubosdz at 2011/07/07 04:42am
showScriptName will not suffice?

Thanx for pretty formatting, now it's clearer what you want to achieve. Yet, the question is: What is the benefit over setting the built-in paramater for urlManager in configuration:


http://www.yiiframework.com/doc/api/1.1/CUrlManager#showScriptName-detail Cheer, Lubos

#4422 report it
Hermans at 2011/07/07 04:13am
hide index.php

this article to hide index.php url: for example:


to be

#4421 report it
lubosdz at 2011/07/07 03:57am
Unclear purpose, example and .htaccess

Hi, your article is a bit unclear about what is the goal you are trying to reach? Perhaps 1-2 examples would make things clearer:-) Also what is the final content of .htaccess file? (you may want to put it into solid code block pretty formatted). Cheers Lubos

#4418 report it
Mukesh at 2011/07/07 01:44am
more on mod_rewrite

Excellent article on how mod_rewrite works - http://www.workingwith.me.uk/articles/scripting/mod_rewrite#writeComment

From the site - "mod_rewrite is used for rewriting a URL at the server level, giving the user output for that final page. So, for example, a user may ask for http://www.somesite.com/widgets/blue/, but will really be given http://www.somesite.com/widgets.php?colour=blue by the server."

Leave a comment

Please to leave your comment.