Opencart 1.5x - 在产品网址末尾添加“.html”

时间:2017-02-24 13:51:19

标签: php opencart

如何在产品网址的末尾添加扩展名“.html” - 我目前的产品链接:
www.mysite.com/productlink
- 我想成为:
www.mysite.com/productlink.html

我编辑了目录/ controller / common / seo_url.php,产品网址现在有.html但是当我点击一个链接时它说404找不到。我需要做什么?

if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id') || ($data['route'] == 'news/article' && $key == 'news_id')) {
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) .   "'");

if ($query->num_rows) {
    $url .= '/' . $query->row['keyword'] . '.html';                     
    unset($data[$key]);
}       

1 个答案:

答案 0 :(得分:0)

您可以使用.htaccess执行此操作 试试这个:我没有测试过,所以可能需要一些调整。

 RewriteEngine on
 RewriteBase /

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^.]+?)/?$ $1.html [R=301,L,NE]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^.]+)\.html$ index.php?_route_=$1 [L,NC]