所以,我使用的是 1.5.5.1,没有一个关于这个问题的答案解决了我的问题。然而,结合@Jay Gilford、@TheBlackBenzKid和@rkaartikeyen的答案,我想出了一个完全可行的解决方案。
请记住启用@TheBlackBenzKid所示的 seo 网址。
可以在代码下方找到解释。
[php]
类 ControllerCommonSeoUrl 扩展控制器 {
公共函数索引(){
// 添加重写到 url 类
if ($this->config->get('config_seo_url')) {
$this->url->addRewrite($this);
}
// 解码网址
if (isset($this->request->get['_route_'])) {
$parts = explode('/', $this->request->get['_route_']);
foreach ($parts 作为 $part) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE 关键字 = '" . $this->db->escape($part) . "'");
if ($query->num_rows) {
$url = explode('=', $query->row['query']);
if ($url[0] == 'product_id') {
$this->request->get['product_id'] = $url[1];
}
if ($url[0] == 'category_id') {
if (!isset($this->request->get['path'])) {
$this->request->get['path'] = $url[1];
} 别的 {
$this->request->get['path'] .= '_' 。$url[1];
}
}
if ($url[0] == 'manufacturer_id') {
$this->request->get['manufacturer_id'] = $url[1];
}
if ($url[0] == 'information_id') {
$this->request->get['information_id'] = $url[1];
}
} 别的 {
$this->request->get['route'] = 'error/not_found';
}
}
if (isset($this->request->get['product_id'])) {
$this->request->get['route'] = 'product/product';
} elseif (isset($this->request->get['path'])) {
$this->request->get['route'] = 'product/category';
} elseif (isset($this->request->get['manufacturer_id'])) {
$this->request->get['route'] = 'product/manufacturer/info';
} elseif (isset($this->request->get['information_id'])) {
$this->request->get['route'] = '信息/信息';
}别的 {
$this->request->get['route'] = $this->request->get['_route_'];
}
if (isset($this->request->get['route'])) {
返回 $this->forward($this->request->get['route']);
}
}
}
公共函数重写($链接){
$url_info = parse_url(str_replace('&', '&', $link));
$url = '';
$数据 = 数组();
parse_str($url_info['query'], $data);
foreach ($data as $key => $value) {
if (isset($data['route'])) {
if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data ['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == '信息/信息' && $key == 'information_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$价值) 。 ”'”);
if ($query->num_rows) {
$url .= '/' 。$query->row['keyword'];
未设置($data[$key]);
}
} elseif ($key == '路径') {
$categories = explode('_', $value);
foreach ($categories as $category) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'");
if ($query->num_rows) {
$url .= '/' 。$query->row['keyword'];
}
}
未设置($data[$key]);
}
}
}
如果($url){
未设置($data['route']);
$查询 = '';
如果($数据){
foreach ($data as $key => $value) {
$查询 .= '&' 。$键。'=' 。$价值;
}
如果($查询){
$查询 = '?' . 修剪($查询,'&');
}
}
返回 $url_info['scheme'] 。'://' 。$url_info['host'] 。(isset($url_info['port']) ? ':' . $url_info['port'] : '') 。str_replace('/index.php', '', $url_info['path']) 。$网址。$查询;
} 别的 {
$link = str_replace('index.php?route=', '', $link);
返回$链接;
}
}
}
显然,@Jay Gilford和@TheBlackBenzKid解决了在页面上正确写入 url 的问题。
113 号线
$link = str_replace('index.php?route=', '', $link);
但它似乎破坏了 url,因为控制器找不到页面,因此恢复到错误页面。
38 - 40 号线
} 别的 {
$this->request->get['route'] = 'error/not_found';
}
@rkaartikeyen 的解决方案通过将当前路由设置为请求的路由来解决这个问题
51 - 53 号线
别的 {
$this->request->get['route'] = $this->request->get['_route_'];
}