0

使用时

Yii::app()->createUrl('/page/');

它正在向 URL LIKE http://www.sitename// AND http://www.sitename//page添加额外的斜杠

我需要排除两个斜杠,应用程序 url 管理器如下,

'urlManager' => array(
        'urlFormat' => 'path',
        'showScriptName' => false,
        'urlSuffix' => '/',
        'rules' => array(
            'site/news_letter_unsubsubscribe/<id:\w+>' => 'site/news_letter_unsubsubscribe',
            'page/<id:[\w\-]+>' => 'page/index/',
            'site/blog_detail/<id:[\w\-]+>' => 'site/blog_detail',
            'location/<id:[\w\-]+>' => 'location/index',
            'auth/partner_detail/<id:[\w\-]+>' => 'auth/partner_detail',
            //'tour/tour_detail/<id:\w+>/<date:\w+>'=>'tour/tour_detail',
            'activity/activity_detail/<id:[\w\-]+>' => 'activity/activity_detail',
            'activity/compare_detail/<id:[\w\-]+>' => 'activity/compare_detail',
            'tour/tour_detail/<id:[\w\-]+>' => 'tour/tour_detail',
            'tour/compare_detail/<id:[\w\-]+>' => 'tour/compare_detail',
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            'auth/reset_password/<id:\w+>' => 'auth/reset_password',
            'site/linkedin_login/<id:\w+>' => 'site/linkedin_login',

        ),
    )

.htaccess 规则

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
4

2 回答 2

2

在 Yii2 中,您的代码是错误的。您正在阅读文档!例子:

echo \Yii::$app->urlManager->createUrl('page');
于 2014-12-22T07:35:58.850 回答
0

我可以对这个问题进行排序,从请求基本 url 中删除后缀斜杠

谢谢

于 2014-12-22T08:35:41.577 回答