看看这个url规则,可以createUrl,不能解析,是我写错了么?

‘urlManager’=>array(

		'urlFormat'=>'path',


		'urlSuffix'=>'.htm',


		'showScriptName'=>false,


		'rules'=>array(


			'<platform:windows>/<alias:\w+>'=>'software/view',

版本yii的1.17

如果你是使用apache服务器, 你的设置’showScriptName’=>false, 也就说设置了隐藏了index.php文件, 还需要增加重写规则

在你的应用根目录增国 .htaccess 文件,加入下面的内容,如果还是有错语,就好好检查一下对应好你的参数.

‘rules’=>array(

			'<platform:windows>/<alias:\w+>'=>'software/view',



AddDefaultCharset utf-8


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



如果你是使用nginx或是其它Web服务器,在wiki内搜索相关的关键字

我的配置

windows,apache


.htaccess文件

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|png|css|js)$

RewriteRule . index.php [L]


创建

Yii::app()->createUrl(‘software/view’,array(‘platform’=>‘windows’,‘alias’=>$software[‘names’]));


urlmanager配置

‘urlManager’=>array(

		'urlFormat'=>'path',


		'urlSuffix'=>'.htm',


		'showScriptName'=>false,


		'rules'=>array(


			'<platform:windows>/<alias:\w+>'=>'software/view',

)),


在CWebApplication::processRequest中调用UrlManager()->parseUrl的时候出的错

现在证实是只要path模式就出问题,不论是否设置urlSuffix,showScriptName

怎么去找原因呢?

知道原因了

‘alias’=>‘test-alias’,由于包含了’-’,而在urlmanager配置中我写的是

‘<platform:windows>/<alias:\w+>’=>‘software/view’,

\w+ 不包含 ‘-’ 字符

正则的问题,学习了。