EC-CUBEで構築したサイトは商品カテゴリ一覧ページや商品詳細ページのURLが、
「http://サーバ名/products/list.php?category_id=xxx」
「http://サーバ名/products/detail.php?product_id=xxx」
という様に、「~.php?~」とURLにクエリが付けてられている状態になります。
最近のGoogleはクエリ付きURLでも先のページをちゃんとクロールしてくれるという話しですが、
過去のSEOを知る身として、そしてURLがクエリ丸見え状態というのはちょっと恥ずかしさもあります。
何より、SEO対策というのは、どれが本当に効果が表れるかというのはとても分かりずらいものなので、
些細なことでも対策しておいて損は無いということもあり、URLの静的化はやっておいて損は無いでしょう。
何より、サイトのURLが美しくて良いです。
EC-CUBEのURL静的化の現状
Googleなどで検索するればそれらしい記事はたくさん出てきますが、
RSSやsitemap、プラグイン関係まで言及している記事が無かったので、
いきなり完全版にはならないかも知れませんが、一歩一歩進化させていこうと思います。
まず、静的化後のURLをどうするかですが、これも幾つか考えられます。
例えば、
- http://サーバ名/products/list123/
- http://サーバ名/products/list/123
- http://サーバ名/products/list123.html
と言った感じです。
これもSEO的には、ディレクトリが深くない方が良いとか、拡張子が付いていた方が良いなど諸説ありました。
現状としては、SEO的にはどれも変わりは無く、人が見たときにどう感じるかというレベルのようです。
では、「人が見たときに」とは何を考慮すべきか。
URLを見て何のページか分かりやすく、短く、ファイルの中身が何かわかりやすいことだと思います。
したがって、「http://サーバ名/products/list123.html」が一番妥当だと思われます。
具体的な施策手順
1~2は、最近のサーバーであれば設定する必要が無いものが多いはずです。
今の時代に、mod_rewriteやhtaccessが使えないサーバーであれば、移転を検討すべきでしょう。
例)
弊社運営サイト「Gadgetr(ガジェッター)」で見るとこんな感じです。
http://gadget.uassist.co.jp/products/list7.html
http://gadget.uassist.co.jp/products/detail21.html
1. mod_rewriteの有効化
まずは、「mod_rewrite」を使ったURLリライトの設定を行います。
Webサーバー(Apache)でmod_rewriteが有効になっているかを調べましょう。
httpd.confに下記設定がなされているか、もしくはサーバー会社に問い合わせましょう。
[code]LoadModule rewrite_module modules/mod_rewrite.so[/cod]
<h4>2. .htaccessの有効化</h4>
WEBサーバーの公開フォルダに対し、「.htaccess」の有効にします。
httpd.confに下記設定を行ってください。
[code]
<Directory “http公開フォルダのパス”>
AllowOverride All
Options FollowSymLinks
</Directory>
[/code]
3. .htaccessにリライトを設定
EC-CUBEの公開ディレクトリルートの「.htaccess」に下記を追記してください。
[code]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^products/detail([0-9]+).html products/detail.php?product_id=$1&%{QUERY_STRING} [L]
RewriteRule ^products/list([0-9]+).html products/list.php?category_id=$1&%{QUERY_STRING} [L]
[/code]
4. カテゴリーブロックテンプレートの修正
「/data/Smarty/template/default/bloc/category_tree_fork.tpl」を下記のように修正します。
[code]
27行目: <p><a href="<!–{$smarty.const.ROOT_URLPATH}–>products/list.php?category_id=<!–{$child.category_id}–>"~
[/code]
↓
[code]
27行目: <p><a href="<!–{$smarty.const.ROOT_URLPATH}–>products/list<!–{$child.category_id}–>.html"~
[/code]
5. 商品詳細ページURLを示すパラメータ設定の変更
管理画面の「システム設定」→「パラメーター設定」を開き、
「P_DETAIL_URLPATH」という項目を下記のように変更します。
[code]ROOT_URLPATH . "products/detail.php?product_id="[/cod]
↓
[code]ROOT_URLPATH . "products/detail"[/cod]
<h4>6. おすすめ商品ブロックテンプレートの修正</h4>
「/data/Smarty/template/default/bloc/recommend.tpl」を下記のように修正します。
[code]
32行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>">
38行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>">~
[/code]
↓
[code]
32行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>.html">
38行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>.html">~
[/code]
7. 商品一覧テンプレートの修正
「/data/Smarty/template/default/products/list.tpl」を下記のように修正します。
[code]
152行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>">
171行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>">~
193行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>">~
[/code]
↓
[code]
152行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>.html">
171行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>.html">~
193行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrProduct.product_id|u}–>.html">~
[/code]
8. 商品詳細テンプレートの修正
「/data/Smarty/template/default/products/detail.tpl」を下記のように修正します。
[code]
172行目: <a href="<!–{$smarty.const.ROOT_URLPATH}–>products/list.php?category_id=<!–{$arrRelativeCat[r][s].category_id}–>">~
355行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrItem.product_id|u}–>">
361行目: <h3><a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrItem.product_id|u}–>">~
[/code]
↓
[code]
172行目: <a href="<!–{$smarty.const.ROOT_URLPATH}–>products/list<!–{$arrRelativeCat[r][s].category_id}–>.html">~
355行目: <a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrItem.product_id|u}–>.html">
361行目: <h3><a href="<!–{$smarty.const.P_DETAIL_URLPATH}–><!–{$arrItem.product_id|u}–>.html">~
[/code]
9. RSSテンプレートの修正
「/data/Smarty/template/default/rss/products.tpl」を下記のように修正します。
[code]
33行目: <link><!–{$smarty.const.HTTP_URL}–>products/detail.php?product_id=<!–{$arrProduct.product_id}–></link>
36行目: <a href="<!–{$smarty.const.HTTP_URL}–>products/detail.php?product_id=<!–{$arrProduct.product_id}–>" rel="product">
39行目: <div class="product-title"><a href="<!–{$smarty.const.HTTP_URL}–>products/detail.php?product_id=<!–{$arrProduct.product_id}–>" rel="product">~
[/code]
↓
[code]
33行目: <link><!–{$smarty.const.HTTP_URL}–>products/detail<!–{$arrProduct.product_id}–>.html</link>
36行目: <a href="<!–{$smarty.const.HTTP_URL}–>products/detail<!–{$arrProduct.product_id}–>.html" rel="product">
39行目: <div class="product-title"><a href="<!–{$smarty.const.HTTP_URL}–>products/detail<!–{$arrProduct.product_id}–>.html" rel="product">~
[/code]
10. sitemap.phpの修正
「/data/class_extends/page_extends/LC_page_Sitemap_Ex.php」に下記追記します。
[php]
function process()
{
parent::process();
}
}
[/php]
↓
[php]
function process()
{
parent::process();
}
/**
* 全ての商品一覧ページを取得する.
*
* @return array 検索エンジンからアクセス可能な商品一覧ページの情報
*/
public function getAllProducts()
{
// XXX: 商品登録の無いカテゴリは除外する方が良い気もする
$objQuery = SC_Query_Ex::getSingletonInstance();
$sql = ‘SELECT category_id FROM dtb_category WHERE del_flg = 0’;
$result = $objQuery->getAll($sql);
$arrRet = array();
foreach ($result as $row) {
// :TODO: カテゴリの最終更新日を取得できるようにする
$arrPage[‘url’] = HTTP_URL . ‘products/list’ . $row[‘category_id’] . ".html";
$arrRet[] = $arrPage;
}
return $arrRet;
}
/**
* 全ての商品詳細ページを取得する.
*
* @return array 検索エンジンからアクセス可能な商品詳細ページの情報
*/
public function getAllDetail()
{
$objQuery = SC_Query_Ex::getSingletonInstance();
$sql = ‘SELECT product_id, update_date FROM dtb_products WHERE ‘ . SC_Product_Ex::getProductDispConditions();
$result = $objQuery->getAll($sql);
$arrRet = array();
foreach ($result as $row) {
$arrPage[‘update_date’] = $row[‘update_date’];
$arrPage[‘url’] = HTTP_URL . substr(P_DETAIL_URLPATH, strlen(ROOT_URLPATH)) . $row[‘product_id’] . ".html";
$arrRet[] = $arrPage;
}
return $arrRet;
}
}
[/php]
あとは、マイページ、お気に入り、スマホ・フューチャーフォンの対策も必要になるかと思いますが、
続きはまた後日・・・。