Remove the need to write index.php on Yii

☆樱花仙子☆ 提交于 2019-12-24 02:12:15

问题


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



来源:https://stackoverflow.com/questions/20882089/remove-the-need-to-write-index-php-on-yii

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!