使用
时Yii::app()->createUrl('/page/');
它正在为网址添加额外的尾随斜杠LIKE http://www.sitename//和http://www.sitename//page
我需要排除两个斜杠,应用程序网址管理器如下,
'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]
答案 0 :(得分:2)
在Yii2中你的代码错了。您正在阅读doc!例如:
echo \Yii::$app->urlManager->createUrl('page');
答案 1 :(得分:0)
我可以从请求库URL
中删除后缀斜杠来解决此问题由于