OpenCart - 中文论坛

标题: OpenCart完美伪静态方案Version 1.5.5.1实例方案 [打印本页]

作者: nowbe    时间: 2013-9-5 10:04
标题: OpenCart完美伪静态方案Version 1.5.5.1实例方案
最近研究Opencart系统,发现此系统的伪静态竟然不怎么完善。
故综合往年开发者一些经验,自己研究结果,总结如下:
作者: nowbe    时间: 2013-9-5 10:05
Part 1
路径文件/catalog/controller/common/seo_url.php

此文件一共添加3个部分

作者: nowbe    时间: 2013-9-5 10:06
A.查找到

  1. } else {
  2.           $this->request->get['route'] = 'error/not_found';        
  3. }
复制代码
在其代码前添加

  1. if ($url[0] == 'common') {
  2.     $this->request->get['route'] = 'common/'.$url[1];
  3. }

  4. if ($url[0] == 'account' && $url[1] == 'return' && $url[2] == 'insert') {
  5.     $this->request->get['route'] = 'account/'.$url[1].'/'.$url[2];
  6. }elseif ($url[0] == 'account') {
  7.     $this->request->get['route'] = 'account/'.$url[1];
  8. }

  9. if ($url[0] == 'checkout') {
  10.     $this->request->get['route'] = 'checkout/'.$url[1];
  11. }

  12. if ($url[0] == 'information') {
  13.     $this->request->get['route'] = 'information/'.$url[1];
  14. }

  15. if ($url[0] == 'product') {
  16.     $this->request->get['route'] = 'product/'.$url[1];
  17. }
复制代码

作者: nowbe    时间: 2013-9-5 10:08
B.查找到

  1. foreach ($data as $key => $value) {
复制代码
在此代码下方增加

  1. $urlAlias = array(
  2.     'account/register',
  3.     'account/login',
  4.     'account/logout',
  5.     'account/password',
  6.     'account/history',
  7.     'account/edit',
  8.     'account/account',
  9.     'account/wishlist',
  10.     'account/newsletter',
  11.     'account/order',
  12.     'account/forgotten',
  13.     'account/address',
  14.     'account/download',
  15.     'account/transaction',
  16.     'account/return/insert',
  17.     'account/return',
  18.     'account/voucher',
  19.     'account/reward',
  20.     'common/home',
  21.     'checkout/cart',
  22.     'checkout/checkout',
  23.     'information/contact',
  24.     'information/sitemap',
  25.     'product/compare',
  26.     'product/search',
  27.     'product/special',
  28. );
复制代码

作者: nowbe    时间: 2013-9-5 10:14
C.查找到

  1. elseif ($key == 'path') {
复制代码
在其代码前添加

  1. elseif (in_array($data['route'],$urlAlias)) {
  2.     $value = str_replace('/','=',$value);
  3.     $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($value) . "'");
  4.     if ($query->num_rows) {
  5.         $url .= '/' . $query->row['keyword'];                        
  6.         unset($data[$key]);
  7.     }                                       
  8. }
复制代码

作者: nowbe    时间: 2013-9-5 10:19
Part 2
导入SQL对应伪静态文件

sql.zip (508 Bytes, 下载次数: 165)


作者: nowbe    时间: 2013-9-5 10:26
Part 3
如果你是Apache环境
将根目录文件.htaccess.txt改名为.htaccess

如果你是Nginx环境
打开服务器找到对应的Nginx配置文件(默认服务器安装路径/usr/local/nginx/conf/vhost/域名.conf)
键在location ~ .*\.(php|php5)?$字段前添加如下内容(abc.com请换成你自己的域名)

  1. location / {
  2.      if ($host != 'www.abc.com') {
  3.              rewrite ^/(.*)$ https://www.abc.com/$1 permanent;
  4.      }
  5.      try_files $uri @opencart;
  6. }

  7. location @opencart {
  8.      rewrite ^/(.+)$ /index.php?_route_=$1 last;
  9. }

  10.      location /admin/ {
  11.      index index.php;
  12.      }

  13. location ~* (\.(tpl|ini))$ {
  14.        deny all;
  15. }
复制代码

作者: nowbe    时间: 2013-9-5 10:40
本帖最后由 nowbe 于 2013-9-5 10:41 编辑

Part 4
登录你的网站后台(www.abc.com/admin/index.php)


找到  系统设置>>网店设置>>编辑网店>>服务器设置>>高级URL Rewrite 选择开启

对应英文路径不记得了


未完问题大家可以回帖留言。
我在更新此贴。

技术问题可以找我来咨询,一起探讨一下。
nowbe2004#126.com
看到邮件留言我有时间会回复你的。
作者: sunboy    时间: 2013-9-5 20:44
不错,支持下:)
作者: wayoca    时间: 2013-9-8 21:54
亲,这个1.5.6可以用吗?菜鸟?谢谢

下载,照抄照搬,祝我成功
作者: wayoca    时间: 2013-9-8 22:09
亲,照抄完了,怎么知道有没有成功
作者: wayoca    时间: 2013-9-8 23:33
本帖最后由 wayoca 于 2013-9-8 23:36 编辑

亲,请了个老师看了下,成功了。     1.5.6

但还有个小问题,就是我的文章   关于优美生活  投递信息 隐私权声明  都链接到 品牌列表或其他地方去了?

商品分类  杯具系列及其下一级分类也都链接错误的地方去了?

咋个办?

谢谢
作者: wayoca    时间: 2013-9-9 08:46
唉,今天一看,一测试每个商品,都链接有错误,到别地儿去了,求救呀
作者: wayoca    时间: 2013-9-9 13:15
楼主,您好。谢谢您的教程。我在oc1.5.6上已经完成测试,成功。

前面出现的链接乱套,现在找到原因。

是我把所有商品基本信息里字段seo都设置成一样的造成的。  这里要求seo是唯一的。这样都改了后就正常了。
再次感谢您的大作。谢谢。
作者: sunboy    时间: 2013-9-25 09:26
你怎么产品seo都设置一样的?这样怎么能行,上次你的帖子好像也是设置一样造成的。

能成功不错,恭喜你哈。
作者: ross    时间: 2013-11-2 14:09
不行啊,到处都是“请求的页面不存在”
作者: ross    时间: 2013-11-2 15:20
原来是还差一点,/catalog/controller/common/seo_url.php原来的第9、10行是
                if (isset($this->request->get['_route_'])) {
                        $parts = explode('/', $this->request->get['_route_']);
改成
                if (isset($this->request->get['route'])) {
                        $parts = explode('/', $this->request->get['route']);

就可以了
作者: ross    时间: 2013-11-3 00:38

  1. # .htaccess
  2. ...
  3. # SEO URL Settings
  4. RewriteEngine On
  5. # If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

  6. RewriteBase /
  7. RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
  8. RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
  9. RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
  10. RewriteCond %{REQUEST_FILENAME} !-f
  11. RewriteCond %{REQUEST_FILENAME} !-d
  12. RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
  13. RewriteCond %{REQUEST_URI} !^index.php
  14. RewriteRule ^([^?]*) index.php?route=$1 [L,QSA]
  15. #...

复制代码


作者: mengwb    时间: 2013-11-9 23:35
按这样配完后,直接访问这些静态地址基本都可以打开相应页面(除了主页不行),没问题。但各连接依然不是静态地址,所以直接点击链接还是带请求参数的页面。
作者: dengweicai    时间: 2013-11-12 01:03
学习下! 支持你们
作者: gogol361    时间: 2013-11-15 17:37
謝謝!
作者: 胡子    时间: 2013-11-21 06:55
先收藏,等网店架起来了再来设置。
作者: 胡子    时间: 2013-11-27 15:03
没搞成功,不知道问题出在哪里,本地调试。
作者: mengwb    时间: 2013-12-3 13:32
以搞定,而且将其做成了插件,方便以后使用。
作者: zzh83916    时间: 2014-1-7 17:18
不错,学习下了哟
作者: liyucmh    时间: 2015-1-11 14:48
mengwb 发表于 2013-12-3 13:32
以搞定,而且将其做成了插件,方便以后使用。

斑竹你好 你搞定的opencart插件 伪静态的 能发我一个吗
作者: heroxd    时间: 2015-2-6 14:28
轻轻的漂过,留下一个大脚印。




欢迎光临 OpenCart - 中文论坛 (https://bbs.opencart.cn/) Powered by Discuz! X3.2