Removing index.php from URL

Alright, so I feel like an idiot asking this, but after reading through the documentation and trying everything I could think of, I’m still stuck  :-[

I’m trying to remove index.php from the URL string. It’s not working, however: navigating to http://localhost/tastebud (would be tastebud/index.php before) doesn’t work. My .htaccess looks like this the same as http://www.yiiframew…uide/topics.url, but with the last line changed per Bethrezen’s comment - neither the original or modified work. 

Here's what I put under components:

		


'urlManager'=>array(


      'urlFormat'=>'path',


      'showScriptName'=>false,


      'rules'=>array(


           '<url:w+>'=>'browse/profile',


      ),


),

Commenting out the rules part did nothing, and rewriting the path worked until I tried to hide index.php. I'm using Windows with Xampplite, and the mod_rewrite in httpd.conf is turned on. I'm a little confused, since nobody else is having this problem: so maybe it's something simple.

If anybody has ideas, that would be great!

What is the error?

Right, forgot to put that in.

"Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500 "

It means your htaccess has problem. What does it look like now?

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 [L]


I've tried it with 'RewriteRule . index.php' instead of the one I have currently, but both failed.

Did you configure your Apache to allow override directives?

Inside your <Directory> you must have to add the option 'AllowOverride all' to htaccess make effect.

Don't forget to restart Apache after that!

Ah, thanks rickgrana. That did the trick. AllowOverride was set to 'all' earlier in the httpd.conf, and then turned down to 'fileinfo' a little later (but that part had missed me).

So it's working now: if anybody else runs into the same problem, check your apache/httpd.conf file and make sure EVERY AllowOverride is set to all under <Directory>.

Looks like I rejoiced too soon: I can get to the root page (localhost/site) no problem, but none of the links work. Entering the old url before removing index.php (http://localhost/tastebud/index.php?r=browse/taste) just takes me back to index.php again, any other URL takes me to my Xampp index page. Any ideas?

I can only say this is apache problem.

Hi

I have this working without any problem, make sure that your apache is set up correctly to allow mod_rewrite and htaccess files and ofcourse the mod_rewrite engine is on.

Config



'urlManager' => array(


  'urlFormat' => 'path',


  'showScriptName' => false,


),


.htaccess



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


This works for me, I wish you luck :)

Chris

Quote

Looks like I rejoiced too soon: I can get to the root page (localhost/site) no problem, but none of the links work. Entering the old url before removing index.php (http://localhost/tastebud/index.php?r=browse/taste) just takes me back to index.php again, any other URL takes me to my Xampp index page. Any ideas?

The behaviour is right. However, your url is wrong. Instead of http://localhost/tas…?r=browse/taste you should use http://localhost/tas…d/browse/taste.

But, for this work out, do the krak3n config.

Quote

The behaviour is right. However, your url is wrong. Instead of http://localhost/tas...?r=browse/taste you should use http://localhost/tas...d/browse/taste.

I was doing what you suggested initially, but it didn't work - that was the one that took me to my xampp index page.

@krak3n: Your configuration didn't work for me either, that was the first thing I tried… weird, huh? 

You need to provide a rewrite base if you are not directly in your wwwroot.



RewriteBase /tastebud/


Quote

I was doing what you suggested initially, but it didn't work - that was the one that took me to my xampp index page. 

Let me understand right: accessing http://localhost/tastebud/browse/taste is getting you to the index page?

My config and .htacess are equal do krak3n.

To make sure that .htacess are making effect, rewrite it with a 'deny all' command and test it. If you access the page, then it is really not working.

In config file URL Manager should be in component array like this:-




'components'=>array(

      ---------------,

      ---------------,

      'urlManager'=>array(

			  'urlFormat'=>'path',

			  'rules'=>array(

					  'post'=>'post/list',

					  'post/<id:\w+'=>'post/read',

				         ),

			  'showScriptName'=>false,

			  'caseSensitive'=>false,

	                 ),

      ---------------,

      ---------------,

                     ),



For rewriting the URL following things should be done in httpd file of Apache:-

1] mod_rewrite module should be uncommented.

2] In <Directory> section AllowOverride None should be replaced with AllowOverride All.

3] Application directory must contain a .htaccess file with following code:-


Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

RewriteBase /Your Application Directory Name/                 //This line must require in your .htaccess.


# 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

Definitely all these will help you.

It’s working for me perfectly.

Why is it necessary to do "IndexIgnore /" ?

Also, I assume this requires mod_autoindex to be enabled (not documented)

Note that if the directory you are in is not your webroot then leave the leading slash off your rewrite rule per this: http://www.yiiframework.com/doc/guide/1.1/en/topics.url#c1245

RewriteRule . index.php

else you will be redirected to the webroot index