这里的问题是url中的加密代码,
我的url是这个,加密代码在最后:
http://localhost/php_pro_106/reload/ByCustomer/mJYwIzoaIGe0R8lAVCqPhG%2Fg0jJFWjiWWdPnkq5VDlY%3D
main.php Url设置:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'caseSensitive'=>false,
'rules'=>array(
'giftcard/<id:'w+>'=>'giftcard/index',
'reload/ByCustomer/<giftcode:'w+>'=>'reload/ByCustomer',
'<controller:'w+>/<id:'d+>'=>'<controller>/view',
'<controller:'w+>/<action:'w+>/<id:'w+>'=>'<controller>/<action>',
'<controller:'w+>/<action:'w+>'=>'<controller>/<action>',
),
),
我的动作在重载控制器:
public function actionByCustomer()
{
echo "test";
print_r($_GET);
}
我得到了:
The requested URL /localhost/reload/ByCustomer/mJYwIzoaIGe0R8lAVCqPhG/g0jJFWjiWWdPnkq5VDlY= was
not found on this server.
实际上问题是ByCustomer/mJYwIzoaIGe0R8lAVCqPhG%2Fg0jJFWjiWWdPnkq5VDlY%3D
,因为它是加密的。我该怎么做才能成功呢?
在byCustomer规则中,giftcodes正则表达式匹配单词。但是uri部分mJYwIzoaIGe0R8lAVCqPhG%2Fg0jJFWjiWWdPnkq5VDlY%3D
不是一个单词,因为它包含像%这样的字符。它看起来像一个url编码的字符串,%2f是/
, %3d是=
。然而,所有这些字符并不是一个单词。
试试这个规则:
'reload/ByCustomer/<giftcode:.+>'=>'reload/ByCustomer',
它匹配reload/ByCustomer/
之后的任何字符。
我得到了它的解决方案,为此我必须改变我的编码和解码方法:
问题是由于一些字符在编码Url中存在。所以,我必须替换这些字符
在main.php中的Url管理器如下:
'reload/ByCustomer/<giftcode>'=>'reload/ByCustomer',
apache在URL中有%2F的问题,它总是返回404,php脚本没有执行。
编辑:有一个解决方案,但它要求您至少可以为您的虚拟主机编辑apache配置文件(我当时没有)。然后,您必须在<VirtualHost>
中添加AllowEncodedSlashes On
。也可以全局设置。
如果你不想这样做
这些链接帮助我:
Stack over flow Solution1
Stack over flow solution2
谷歌集团