Remove the need to write index.php on Yii

2019-07-15 12:09发布

问题:

I've setup Yii 1.1.x on my WAMP environment, it all works however I am still need to use index.php in the URL for the routing to work.

Mod rewrite has been enabled in my WAMP config.

Can anyone explain what I need to alter to allow me to run the app without having index.php in the URL itself?

My Yii config is as follows:

// uncomment the following to enable URLs in path-format        
urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
    'showScriptName'=>false,
),

My htaccess looks like the following:

 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

回答1:

change your .htaccess file to this

<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Don't perform redirects for files and directories that exist:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For everything else, redirect to index.php:
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</ifModule>

Note:- save it as www/yourProject/.htaccess