Problem Hiding index.php, error: The requested URL /sc2/post/index.html was not found on this server.

I was extending the Yii Blog example with some other models.

When I try to enable the "Hiding index.php" feature explained in http://www.yiiframework.com/doc/guide/topics.url

I added the .htaccess with this content


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

And this is the content of the urlManager


'urlManager'=>array(

			'urlFormat'=>'path',

			'showScriptName' => false,

			'urlSuffix' => '.html',

			'rules'=>array(

        		'post/<id:\d+>/<title:.*?>'=>'post/view',

				'replay/<id:\d+>/<title:.*?>'=>'replay/view',

				'ustream/<id:\d+>/<title:.*?>'=>'ustream/view',

        		'posts/<tag:.*?>'=>'post/index',

				'<view>'=>'site/page',

        		'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

				

        	),

        	

			

		),

Then I refresh the main index and when I try to go to the post index page ( http://localhost/sc2/post/index.html ) it says:

Not Found

The requested URL /sc2/post/index.html was not found on this server.

How can I resolve this bug?

Thank you very much, Emanuele.

apache’s mod_rewrite is turned off by default in wamp. Turn it on then try again.

I use this convenient setup




Options +FollowSymLinks

IndexIgnore */*

DirectoryIndex index.php


<IfModule mod_rewrite.c>

	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?url_rewrite_on=1&%{QUERY_STRING}

	RewriteRule ^$ index.php?url_rewrite_on=1&%{QUERY_STRING}

</IfModule>






...

'showScriptName'=>!(isset($_GET['url_rewrite']) && $_GET['url_rewrite']==1),

...



so index.php is only hidden when mod_rewrite is enabled or i explicitly type a url with this in it:

url_rewrite_on=1

if you do that and do not want anyone to explicitly try to manipulate hiding your index.php then make url_rewrite_on a random string that is unlikely to be guessed easily and reflect the change in your config.php and .htaccess

I had some problems with this as well (I know hardly anything about the .htaccess contents), in particular with the code StErMi shows.

Somewhere I found the .htaccess below and this works for me.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

I’m using LAMP and mod_rewrite is on. Like explained I’m using the same .htcaccess used in the Yii Official guide.

There are similar discussion in this forum

On some configuration the last .htaccess line




RewriteRule . index.php



is not working, try to change it to




RewriteRule ^.*$ index.php