Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii1中的Url管理器和Htaccess_Php_.htaccess_Yii1.x - Fatal编程技术网

Php Yii1中的Url管理器和Htaccess

Php Yii1中的Url管理器和Htaccess,php,.htaccess,yii1.x,Php,.htaccess,Yii1.x,我有这样的url: www.studyenglish/index.php?r=site/lesson&act=read&id=1 我希望更改为: www.studyenglish/site/lesson/read 我已经在url管理器config/main.php中添加了这个脚本 'urlManager'=>array( .... 'showScriptName'=>false, .... ), 并将此脚本添加到.htaccess

我有这样的url:

www.studyenglish/index.php?r=site/lesson&act=read&id=1

我希望更改为:

www.studyenglish/site/lesson/read

我已经在url管理器config/main.php中添加了这个脚本

'urlManager'=>array(
       ....
       'showScriptName'=>false,
        ....
    ),
并将此脚本添加到.htaccess中

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 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中工作,如下所示:

www.studyenglish/index.php?r=site/lesson

将是:

www.studyenglish/site/lesson

那么,如何更改此url

www.studyenglish/index.php?r=site/lesson&act=read&id=1

将来

www.studyenglish/site/lesson/read

希望有人能帮忙。
谢谢…

UrlManager中有规则,您可以定义自己的规则。 您的UrlManager可能如下所示

'urlManager' => array(
'urlFormat' => 'path',
    'rules' => array(
        'gii' => 'gii/index',
        'gii/<controller:\w+>/<action:[\w-]+>' => 'gii/<controller>/<action>',
        '<controller:\w+>/<id:\d+>' => '<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
        'site/lesson/<act:\w+>/<id:\d+>' => 'site/lesson'
        //
public function actionLesson($act,$id){
    //
}

更改您的
urlManager
如下:

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            'rules'=>array(),
        ),
Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 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]
您的
.htaccess
如下:

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            'rules'=>array(),
        ),
Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 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]

将.htaccess更改为:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 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?r=$1 [L]

并在URL管理器中添加适当的规则。

我得到的错误属性“CUrlManager.routes”未定义。我在main.php->log->routes中添加了这个脚本。我已经编辑了答案,以向您显示行的确切位置。同时删除你的答案,这不是一个定义上的答案,只是对问题的解释。如果需要,请编辑问题