How to remove index.php from URL

(Dr Dumb99) #1


Iam newbie to YII framework and using its latest vesion 1.1.0. I have enabled seo friendly urls through config file. My next problem is that how can I remove 'index.php' from URL. Iam using following .htaccess file.

Options +FollowSymLinks

IndexIgnore */*

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

Can some one guide me how to solve this.

Thanks in advance

(Arekandrei) #2

.htaccess is ok.

Is apache rewrite engine turned on?

Also could be nice to see your config file.

(Dr Dumb99) #3

Yes Module_Rewrite is enabled on my WAMP server.

Following is my config file.


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(


	'name'=>'My Web Application',

	// preloading 'log' component


	// autoloading model and component classes





	// application components



			// enable cookie-based authentication



		// uncomment the following to enable URLs in path-format












			'connectionString' => 'sqlite:protected/data/testdrive.db',


		// uncomment the following to use a MySQL database



			'connectionString' => 'mysql:host=localhost;dbname=testdrive',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',




			// use 'site/error' action to display errors








					'levels'=>'error, warning',


				// uncomment the following to show log messages on web pages









	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']


		// this is used in contact page




(Jerry2801) #4



(Dr Dumb99) #5

Thanks for guidance.

One more thing.

How can change static pages urls. E.g; following is url for About page.


How can I change it to more friendly url by removing ‘?’ sign from url.

Thanks in advance

(Jerry2801) #6

add route:


(Lesboys) #7

Thanks for the tip but being a newbie it’s all a little fuzzy to me!

So can you let me know where to add the above view route,

I can’t seem to find info on it in the docs anywhere.

(Mh) #8


(Lesboys) #9

Thanks Mike.

Really helps to know where to look:)

Now all I have to do is figure out what it all means - ah the joy of learning something new :unsure:

(Phuong Nguyen Itvn) #10

thank very much.i’m yii beginer

(Rodrigo Ferreira) #11


I’ve been trying to enable Yii under https on Apache2 and everything works fine,

except that the usual .htaccess to hide index.php (as shown in the initial post)

does not seem to work.

If I move the rewrite rules to the virtual host config, it works; but I would

rather have them in the .htaccess file.

Anyone experiences this? Any suggestions?


(Mh) #12

This usually means, that AllowOverride is set to None for this directory (or one of its parents directories) in your Apache config, which means: Do not allow to override settings in a .htaccess file.

(Rodrigo Ferreira) #13

Thanks man for the precise observation, it works!

I tried to match the settings for both my http and https virtual hosts when setting up SSL,

and, indeed, for some reason I overlooked "AllowOverride"… my bad.

(Luca Udinesi) #14

Hi, I tried a bit with your hint and I ended up adding this line:


in the urlManager portion in config/main, placing it before the other rules.

The result is now that the default "about" page have this url:


And the rest of the site works.

My question is: Did I do that correctly? It doesn’t look like your code at all…!!!

(Simmonian) #15

I know this is a year old. But wanted to say it’s great there’s a good community here as I look around through the forum. If you had not asked the OP for his config file, the documentation or my interpretation of it had me actually trying to modify files in the framework to get this to work.After reading this I looked at the config file and saw the code already auto generated and commented out. Both the tour videos and the first couple chapters of the new yii book say it is easy to do but they don’t tell how to do it. Frustrating but glad there’s an active community. I’m really liking Yii since I started this morning. :slight_smile:

(Wpswebinfo) #16

To remove “index.php” from your URLs we need to tell the server to parse all files as though they did have “index.php” in the URL, but just not show it to the user.

RewriteEngine on

RewriteCond $1 ^(weblog|member|search|Forum_Name|TemplateGroup_4_Name|TemplateGroup_5_Name|P[0-9]{2,8}) [NC]

RewriteRule ^(.*)$ /index.php/$1 [L]

(Angela Arrie) #17

where i must put that .htaccess file??

(Adinugro) #18

Put .htaccess on your root application folder. On the same level as the index.php, index-test.php.

(Amr M Draz) #19


I enabled the url manager and the index.php part in the url gets removed and works fin

my .htacsses file

RewriteEngine on

# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php)

# otherwise forward it to index.php

RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]

the url manager works fine ut index.php doesn’t go away in the url

so I added when I have showScriptName set to false in my config/main.php file









but now I get a 404 error whenever I click a link(because it removed index.php from the url)

(Sagar Krupahb2000) #20


I have a problem with .htaccess file. I have made the following configuration changes.

  1. removed the commented lines for rewrite in httpd.conf file.

    LoadModule rewrite_module modules/

  2. Created new .htaccess file in the root directory of the website (In the place where we have index.php file) with following content:

RewriteEngine on

if a directory or a file exists, use it directly



RewriteCond $1 !^(index.php)

otherwise forward it to index.php

RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]

(I am using windows OS).

  1. Updated the main.php in config with following info:











I am getting 404 error…

Please help me on this.

Thank you.