试图让我的搜索结果页面SEO友好..看起来很基本,但我的标签重写规则是冲突的。
(也使用product/search
路由器) - 禁用标签重写,搜索仍然无法正常工作..它显示它想要的任何内容,即使我搜索不存在的项目。 (在普通的index.php?route = product / search URL下)不会发生此行为
htaccess的:
RewriteRule ^tags/([^/]*)$ index.php?route=product/search&tag=%{QUERY_STRING} [L]
RewriteRule ^search/([^/]*)$ index.php?route=product/search&search=%{QUERY_STRING} [L]
目录/控制器/启动/ seo_url.php:
} elseif ($data['route'] == 'product/search' && $key == 'tag') {
$url .= '/tags/' . str_replace(' ','-',$value);
unset($data[$key]);
} elseif ($data['route'] == 'product/search' && $key !== 'tag') {
$url .= '/search/' . str_replace(' ','-',$value);
unset($data[$key]);
//....
有没有办法在不选择其中一条路线的情况下重写这两条路线?
使用Opencart 2.3.0
答案 0 :(得分:0)
<强>目录/控制器/启动/ seo_url.php 强>
<强>找到:强>
$this->request->get['route'] = 'error/not_found';
添加强>
if (strpos($this->request->get['_route_'], 'tag/') !== false) {
$this->request->get['route'] = 'product/search';
$this->request->get['tag'] = str_replace('tag/','',$this->request->get['_route_']);
}
elseif (strpos($this->request->get['_route_'], 'search/') !== false) {
$this->request->get['route'] = 'product/search';
$this->request->get['search'] = str_replace('search/','',$this->request->get['_route_']);
}
else {
$this->request->get['route'] = 'error/not_found';
}
<强> htaccess的:强>
RewriteRule ^tag/([^/]*)$ index.php?route=product/search&tag=$1 [L]
RewriteRule ^search/(.*)$ index.php?route=product/search&search=$1 [L]