搜索
开启辅助访问 切换到宽版

QQ登录

只需一步,快速开始

扫一扫,访问微社区

注册 找回密码
查看: 16049|回复: 13
打印 上一主题 下一主题

OpenCart SEO优化教程

  [复制链接]
跳转到指定楼层
楼主
发表于 2011-5-16 09:34:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Opencart 使用伪静态
服务器必须要支持mod_rewrite
OpenCart 只支持产品 ,Infomation , 分类 静态化.其他页面的静态方案在第二节细讲.

一、产品 ,Infomation , 分类 静态化
1.登录opencart admin panel, 打开 System==>Server 选择Use SEO URL’s: 为 Yes
2.新建一个文件文件名为 .htaccess
内如如下


Options +FollowSymlinks        Options -Indexes        Prevent Direct Access to files        <FilesMatch "\.(tpl|ini|log|txt)">           Order deny,allow           Deny from all        </FilesMatch>         #SEO URL Settings        RewriteEngine On        RewriteBase /opencart/ #这个是文件根目录, 根据你自己的站点而定.        RewriteCond %{REQUEST_FILENAME} !-f        RewriteCond %{REQUEST_FILENAME} !-d        RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

3.此时你的网店设定已经完成,现在只用添加产品的时候填写SEO Keyword 就可以实现 伪静态了.(请看第四小节)
(SEO的优化 其实不再与后缀名一定是html,只要是不变的就可以了.像下面这个对SEO来讲是没问题的)
4.现在我们点击一下产品例如
Canon EOS 5D

进入后台 Catalog==>roducts==>找到这个产品
编辑它,选择Data项,找到SEO Keyword,输入你想要的 url
例如 eos.html
在这里填写你要的字符串就好了, 可以带一个扩展名,例如html
现在去首页在点击这个产品 URL 变成
https://127.0.0.1/opencart/desktops/eos.html

这样是不是很好看.
产品伪静态到此结束.
二、其他页面伪静态其他页面的伪静态 就需要一些数据库知识了,还有要会修改些代码
需要修改一个文件
/opencart/catalog/controller/common/seo_url.php
一个数据库表,前缀._url_alias 这个表,一下简称url_alias
下面拿主页和会员Account这两个举例如何实现伪静态

主页这个比较简单,假如这样访问首页
https://127.0.0.1/opencart/index.php?route=common/home
注意这个route=common/home
在 url_alias 表中插入一行
Query                 keyword
common=home    index.html
注意对应列,
url_alias有两列,query 真实的地址, keyword 是伪静态的地址, 也可以写成 common/index.html 只要符合 URL规范

插入完成后,需要在 Controller seo_url.php中加入一段代码就可以访问
文件路径/opencart/catalog/controller/common/seo_url.php


} else {        $this->request->get['route' = 'error/not_found';}

的上面加入

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



此时就可以使用
https://127.0.0.1/opencart/index.html 访问了
Account 的做法跟 Common 一样的道理 例如
https://127.0.0.1/opencart/index.php?route=account/account
那么就在数据库中插入

Query                           keyword
account=account         account.html
/opencart/catalog/controller/common/seo_url.php
要加入判定的代码

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



这里需要特别注意,
https://127.0.0.1/opencart/index.php?route=account/account
https://127.0.0.1/opencart/index.php?route=account/edit
https://127.0.0.1/opencart/index.php?route=account/history
这几个地址只用加入一段,因为 他们都是 acoount/ 开头的.

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



不是每个都要加入上面的代码
$url[0] == ’account’ 的意思 就是判定 “/” 之前 是否等于 account

account/account
account/edit

好了以上就可完成伪静态,
只要在地址栏中输入 https://127.0.0.1/opencart/加上你 数据库keyword的值就可以访问对应页面了。

由于,页面上很多使用 固定地址,所以我们要去代码中将 地址改掉,
一般的地址都在/opencart/catalog/controller
先看 common 目录下的,我们先修改首页的地址

Home Log Off Account Basket Checkout
这几个地址都在
/opencart/catalog/controller/common/header.php

$this->data['home' = HTTP_SERVER . 'index.php?route=common/home';$this->data['special' = HTTP_SERVER . 'index.php?route=product/special';$this->data['contact' = HTTP_SERVER . 'index.php?route=information/contact';$this->data['sitemap' = HTTP_SERVER . 'index.php?route=information/sitemap';$this->data['account' = HTTPS_SERVER . 'index.php?route=account/account';$this->data['logged' = $this->customer->isLogged();$this->data['login' = HTTPS_SERVER . 'index.php?route=account/login';$this->data['logout' = HTTP_SERVER . 'index.php?route=account/logout';$this->data['cart' = HTTP_SERVER . 'index.php?route=checkout/cart';$this->data['checkout' = HTTPS_SERVER . 'index.php?route=checkout/shipping';


例如 home
我们可以修改成

$this->data['home' = HTTP_SERVER . 'index.html';



我不是很建议把地址直接修改成 index.html,如果日后你又要还原,就麻烦了
我们可以在根目录中的 config.php 中定义
define(‘HOME’, ’index.html’);
在header.php中就可以

$this->data['home' = HTTP_SERVER . HOME;



日后只要的config.php中修改定义,就可以了

define('HOME', 'index.php?route=common/home');




自己选择.整个静态化到此为止了, 我的版本是 1.4.9
其实这个应该跟版本没什么关系,如果有什么不懂的可以 QQEmail 告诉我

QQ 83390286
MSN: niuzhenhua@hotmail.com
Gmail: kingplesk@gmail.com

资料转自 https://kingplesk.org/archives/71
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏3 分享分享 支持支持 反对反对
回复

使用道具 举报

沙发
发表于 2011-5-16 14:08:10 | 只看该作者
顶啊……这个好
回复 支持 反对

使用道具 举报

板凳
发表于 2011-5-16 14:40:12 | 只看该作者
很好啊,我有一点不明的地方时。seo_url.php 的修改跟header.php的修改有关系吗?
回复 支持 反对

使用道具 举报

地板
发表于 2011-7-12 14:41:21 | 只看该作者
的确是个好东西
回复 支持 反对

使用道具 举报

5#
发表于 2012-2-19 05:05:32 | 只看该作者
必须学会的一个技巧。
回复 支持 反对

使用道具 举报

6#
发表于 2012-3-6 23:47:43 | 只看该作者
你好,为什么我System==>Server 。没有“Server”这一项啊
回复 支持 反对

使用道具 举报

7#
发表于 2012-4-4 02:31:45 | 只看该作者
好东西啊~必须顶
回复 支持 反对

使用道具 举报

8#
发表于 2012-12-19 17:30:55 | 只看该作者
好贴留名
回复 支持 反对

使用道具 举报

9#
发表于 2012-12-31 18:19:17 | 只看该作者
图片都看不到啊!!!!
回复 支持 反对

使用道具 举报

10#
发表于 2013-1-9 01:09:31 | 只看该作者
稍微有点复杂,有没有一劳永逸的方法咧?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

QQ|手机版|OpenCart - 中文官方网站 ( 蜀ICP备09033774号|人工智能

GMT+8, 2024-4-27 03:48 , Processed in 0.084507 second(s), 23 queries , Gzip On.

快速回复 返回顶部 返回列表