|
一、產品,Infomation ,分類靜態化
1.登錄opencart admin panel,打開System==>Server選擇Use SEO URL's:為Yes
2.新建一個文件文件名 為.htaccess
內如如下
- # 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
- # 2. In your opencart directory rename htaccess.txt to .htaccess.
- # For any support issues please visit: http://www.opencart.com
- Options +FollowSymlinks
- # Prevent Directoy listing
- Options -Indexes
- # Prevent Direct Access to files
- <FilesMatch "\.(tpl|ini|log)">
- Order deny,allow
- Deny from all
- </FilesMatch>
- # SEO URL Settings
- RewriteEngine On
- # If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
- RewriteBase /
- RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
- RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
- RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
- RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
複製代碼- RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA] 修改成
- 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
要加入判定的代碼
- if ($url[0 == 'account') { $this->request->get['route' = 'account/'.$url[1;}
複製代碼
這裡需要特別注意,
這幾個地址只用加入一段,因為他們都是acoount/開頭的.
- 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
- $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');
複製代碼 |
|