我对过滤系统中的编码符号有问题。
例如,如果第一个过滤器是针对品牌的,而品牌名称是'Head &肩膀‘,则url应该类似于网站/类别/品牌头+%26+肩部,但只有当url为website/category/brand-head-%252526+shoulders.时,该过滤器才能工作。
如果有另一个过滤器选择,例如高度,品牌过滤器工作,如果url是website/category/brand-head-%25252526+shoulders等,我必须添加另外25之前的百分比标志。
这是品牌过滤代码
if($brand == false){
$data['brands'] = array();
$brands = $attributes->getBrands($av_list, $_GET['c']);
$brandTotalCnt = 0;
if(!empty($brands)){
foreach ($brands as &$brand) {
if($av_list){
$cur_av_list = $av_list . $brand['brand'];
$cur_av_uri = $_GET['av'] . $brand['brand'];
} else {
$cur_av_list = $brand['brand'];
$cur_av_uri = $brand['brand'];
}
$tmp_uri = explode('/', $ln_uri);
$tmp_uri_array = $attributes->remove_items_by_value($tmp_uri, 'brand');
$new_uri = implode('/', $tmp_uri_array);
$brandTotalCnt += $brand['num'];
$data['brands'][] = array(
'brand' => ucwords(strtolower($brand['brand'])),
'num' => $brand['num'],
'href' => $url->link('/c/'.$_GET['c'], '/brand-'. urlencode(strtolower($brand['brand'].'1')). $new_uri)
);
}
}
$data['brandTotalCnt'] = $brandTotalCnt;
}每个过滤器的Urldecode
if(isset($brand)){
$sql .= " AND brand = '".urldecode($brand)."'";
}
if(isset($gramaj)){
$height= $_GET['height'];
$sql .= " AND height= '".urldecode($height)."'";
}这是我的htaccess
# rewrite /category/brand-mybrand/country-mycountry/offer-yes/new-yes
# to /index.php/brand-mybrand/country-mycountry/offer-yes/new-yes?c=category
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^c/([^/]+)/([^-]+.+)/?$ /index.php/$2?c=$1 [L,QSA]
# rewrite /index.php/brand-mybrand/country-mycountry/offer-yes/new-yes?c=category
# converts any /name-val/ to query parameter name=val in every rewrite
# stopping when there is no part left after /index.php
RewriteRule ^(index\.php)/([^-]+)-([^/]+)(/.*)?$ /$1$4?$2=$3 [L,QSA]发布于 2015-05-20 13:52:39
当它填充$_GET[]时,PHP会自动解析查询字符串,并在启动时解码这些值。
在生成URL时,urlencode()值是正确的,但不能urldecode()从$_GET[]中选择的值。
更新:
正如Apache 文档中所解释的那样
mod_rewrite必须在映射它们之前取消转义URL,因此在应用时反向引用是未转义的。
如果重写规则获取路径的一部分并将其放入查询字符串,则标志[B] (转义反向引用)指示引擎使用未转义的URL来匹配该规则。
对于您的问题,您有两个解决方案:
-),您就安全了;[B]标志添加到受影响的重写规则中:
RewriteRule ^c/(^/+)/(^-+.+)/?$ /index.php/$2?c=$1 L,QSA,Bhttps://stackoverflow.com/questions/30349868
复制相似问题