TShopping

 找回密碼
 註冊
搜索
查看: 2607|回復: 0
打印 上一主題 下一主題

[教學] OpenCart SEO優化 偽靜態 教程

[複製鏈接]
跳轉到指定樓層
1#
發表於 2014-12-22 15:56:37 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
一、產品,Infomation ,分類靜態化
1.登錄opencart admin panel,打開System==>Server選擇Use SEO URL's:為Yes

2.新建一個文件文件名 ​​為.htaccess
內如如下  

  1. # 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
  2. # 2. In your opencart directory rename htaccess.txt to .htaccess.
  3. # For any support issues please visit: http://www.opencart.com
  4. Options +FollowSymlinks
  5. # Prevent Directoy listing
  6. Options -Indexes

  7. # Prevent Direct Access to files
  8. <FilesMatch "\.(tpl|ini|log)">
  9. Order deny,allow
  10. Deny from all
  11. </FilesMatch>
  12. # SEO URL Settings
  13. RewriteEngine On
  14. # If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
  15. RewriteBase /
  16. RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
  17. RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
  18. RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
  19. RewriteCond %{REQUEST_FILENAME} !-f
  20. RewriteCond %{REQUEST_FILENAME} !-d
  21. RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
  22. RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
複製代碼
  1. RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA] 修改成

  2. RewriteRule ^(.*)\.html$ index.php?_route_=$1 [L,QSA]
複製代碼

3.此時你的網店設定已經完成,現在只用添加產品的時候填寫SEO Keyword就可以實現偽靜態了.(請看第四小節)
(SEO的優化其實不再與後綴名一定是html ,只要是不變的就可以了.像下面這個對SEO來講是沒問題的)

4.現在我們點擊一下產品例如
Canon EOS 5D

進入後台Catalog==>Products==>找到這個產品
編輯它,選擇Data項,找到SEO Keyword,輸入你想要的url
例如eos.html
在這裡填寫你要的字符串就好了,可以帶一個擴展名,例如html
現在去首頁在點擊這個產品URL變成
http://127.0.0.1/opencart/desktops/eos.html
這樣是不是很好看.
產品偽靜態到此結束.
二、其他頁面偽靜態其他頁面的偽靜態就需要一些數據庫知識了,還有要會修改些代碼
需要修改一個文件
/opencart/catalog/controller/common/seo_url.php
一個數據庫表,前綴._url_alias這個表,一下簡稱url_alias
下面拿主頁和會員Account這兩個舉例如何實現偽靜態

主頁這個比較簡單,假如這樣訪問首頁
http://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;}


此時就可以使用
http://127.0.0.1/opencart/index.html訪問了
Account的做法跟Common一樣的道理例如
http://127.0.0.1/opencart/index.php?route=account/account

那麼就在數據庫中插入
Query keyword
account=account account.html
/opencart/catalog/controller/common/seo_url.php
要加入判定的代碼

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



這裡需要特別注意,
http://127.0.0.1/opencart/index.php?route=account/account
http://127.0.0.1/opencart/index.php?route=account/edit
http://127.0.0.1 /opencart/index.php?route=account/history

這幾個地址只用加入一段,因為他們都是acoount/開頭的.

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


不是每個都要加入上面的代碼
$url[0] == 'account'的意思就是判定“/”之前是否等於account

account/account
account/edit

好了以上就可完成偽靜態,
只要在地址欄中輸入http://127.0.0.1/opencart/加上你數據庫keyword的值就可以訪問對應頁面了。

由於,頁面上很多使用固定地址,所以我們要去代碼中將地址改掉,
一般的地址都在/opencart/catalog/controller
先看common目錄下的,我們先修改首頁的地址

Home Log Off Account Basket Checkout
這幾個地址都在
/opencart/catalog/controller/common/header.php

  1. $this->data['home' = HTTP_SERVER . 'index.php?route=common/home';
  2. $this->data['special' = HTTP_SERVER . 'index.php?route=product/special';
  3. $this ->data['contact' = HTTP_SERVER . 'index.php?route=information/contact';
  4. $this->data['sitemap' = HTTP_SERVER . 'index.php?route=information/sitemap';
  5. $this-> data['account' = HTTPS_SERVER . 'index.php?route=account/account';
  6. $this->data['logged' = $this->customer->isLogged();
  7. $this->data['login' = HTTPS_SERVER . 'index.php?route=account/login';
  8. $this->data['logout' = HTTP_SERVER . 'index.php?route=account/logout';
  9. $this->data['cart' = HTTP_SERVER . 'index.php?route=checkout/cart';
  10. $this->data['checkout' = HTTPS_SERVER . 'index.php?route=checkout/shipping';
複製代碼



例如home
我們可以修改成


  1. $this->data['home' = HTTP_SERVER . 'index.html';
複製代碼


我不是很建議把地址直接修改成index.html,如果日後你又要還原,就麻煩了
我們可以在根目錄中的config.php中定義
  1. define('HOME', 'index.html');
複製代碼

在header .php中就可以

  1. $this->data['home' = HTTP_SERVER . HOME;
複製代碼



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

  1. define('HOME', 'index.php?route=common/home');
複製代碼

 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-20 13:21 , Processed in 0.117083 second(s), 22 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表