我正在使用修改后的 URL 管理器,在 URL 地址中嵌入语言信息。这是我的配置:
'urlManager'=>array(
'class'=>'cms.components.UrlManager',
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<action:\w+>/<language:(sk|en)>/*' => '<controller>/<action>',
),
),
和 URL 管理器:
class UrlManager extends CUrlManager
{
public function createUrl($route, $params = array(), $ampersand = '&')
{
if (!isset($params['language']))
{
if (Yii::app()->user->hasState('language'))
{
Yii::app()->language = Yii::app()->user->getState('language');
}
else if (isset(Yii::app()->request->cookies['language']))
{
Yii::app()->language = Yii::app()->request->cookies['language']->value;
}
$params['language'] = Yii::app()->language;
}
return parent::createUrl($route, $params, $ampersand);
}
}
CListView 代码:
$this->widget('zii.widgets.CListView', array(
'viewData'=>array('asset'=>$this->layout_asset),
'dataProvider'=>$provider,
'itemView'=>'common.blocks.sportlistview.item_render',
'summaryText'=>'',
'ajaxUpdate'=>true,
'enablePagination'=> true,
'enableSorting'=>false,
'sortableAttributes'=>array(),
'template'=>'{items}{pager}',
'emptyText' => '',
));
这是我当前在分页中的链接行为(带描述):
http://example.com/web/page/render/sk/slug/test-page /* Original URL */
http://example.com/web/page/render/sk/slug/test-page/sk/slug/test-page/ /* URL of the first page in pagination on the original URL */
http://example.com/web/page/render/sk/slug/test-page/sk/slug/test-page//page/2 /* URL of the second page in pagination on the original URL */
http://example.com/web/page/render/sk/ajax/yw1/slug/test-page/sk/slug/test-page/sk /* URL of the first page in pagination on the second URL */
http://example.com/web/page/render/sk/ajax/yw1/slug/test-page/sk//test-page/sk/yw1/slug/page/2 /* URL of the second page in pagination on the first page modified URL */
http://example.com/web/page/render/sk/ajax/yw1/slug/test-page/sk/ajax/test-page/sk/yw1/slug
.htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
# PAGE REDIRECT TO WEB FOLDER
RewriteCond %{HTTP_HOST} ^(?:www.)?example.com$
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_URI} !^/resources/
RewriteCond %{REQUEST_URI} !^/backend/
RewriteRule ^(.*)$ /web/$1 [NC,L,NS]
# RESOURCES REDIRECT
RewriteCond %{HTTP_HOST} ^static.example.com$
RewriteRule ^(.*)$ http://example.com/resources/$1 [NC,L,NS]
# ADMIN REDIRECT
RewriteCond %{HTTP:Host} ^admin.example.com$
RewriteCond %{REQUEST_URI} !^/backend/
RewriteRule ^(.*)$ backend/$1 [NC,L,NS]
主要应用程序位于www.example.com/web
.
我应该怎么做才能防止这种行为?