Yii Framework如何隐藏index.php?

时间:2016-11-20 16:53:24

标签: php .htaccess yii

我的.htaccess内容如下:

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

和url manager是:

'urlManager' => array(
        'urlFormat' => 'path',
        'showScriptName' => false,
        'urlSuffix' => '.jsp',
        'caseSensitive' => false,

但是当我访问除主页之外的所有子页面和链接时,没有index.php它不起作用。 怎么解决这个问题?

2 个答案:

答案 0 :(得分:0)

Set main.php in your yii configuration, at component :

'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
 'caseSensitive'=>false,        

),

如果这不起作用,您可以将下面的脚本添加到主配置文件中的urlManager数组中。

例如。 -

'routeVar'=>'route'

答案 1 :(得分:0)

请使用以下代码修改您的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
#RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

使用以下代码更改protected / config / main.php [url manager block]

'urlManager' => array(
    'urlFormat' => 'path',
        'showScriptName'=>false,
        'rules' => array(
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
        ),
    ),
相关问题