$(function(){ var pattern ={ // /products/list.php の変換マスタ // "カテゴリID":"変換後ファイル名" "category_list":{ "11" :"handball", "67" :"stream/handball" }, "products_category_list":{ "88" :"handball", "89" :"handball", "90" :"handball", "91" :"handball", "539" :"handball", "540" :"handball", "541" :"handball", "542" :"handball", "543" :"handball", "544" :"handball", "545" :"handball", "546" :"handball", "547" :"handball", "548" :"handball", "549" :"handball", "550" :"handball", "551" :"handball", "552" :"handball", "1153" :"handball", "1154" :"handball", "1155" :"handball", "1156" :"handball", "1157" :"handball", "1158" :"handball", "1430" :"handball", "1431" :"handball", "1432" :"handball", "1677" :"stream/handball", "1678" :"stream/handball", "1679" :"stream/handball", "1680" :"stream/handball", "2087" :"stream/handball", "2088" :"stream/handball", "2089" :"stream/handball", "2090" :"stream/handball", "2091" :"stream/handball", "2092" :"stream/handball", "2093" :"stream/handball", "2094" :"stream/handball", "2095" :"stream/handball", "2096" :"stream/handball", "2097" :"stream/handball", "2098" :"stream/handball", "2099" :"stream/handball", "2100" :"stream/handball", "2631" :"stream/handball", "2632" :"stream/handball", "2633" :"stream/handball", "2634" :"stream/handball", "2635" :"stream/handball", "2636" :"stream/handball", "2906" :"stream/handball", "2907" :"stream/handball", "2908" :"stream/handball", "3051" :"stream/handball", "3191" :"stream/handball", "3192" :"stream/handball", "3193" :"stream/handball", "3194" :"stream/handball", "3195" :"stream/handball", "3196" :"stream/handball", "3197" :"handball", "3198" :"handball", "3199" :"handball", "3200" :"handball", "3201" :"stream/handball", "3202" :"stream/handball", "3203" :"stream/handball", "3204" :"stream/handball", "3205" :"handball", "3206" :"handball", "3207" :"handball", "3208" :"handball" } }; /* リンクURL書き換え */ $('a').each(function() { var ret = $(this).attr('href'); if(ret){ var res_data = null; var cat_res = ret.match(/\/products\/list\.php\?(.*)category_id=(\d{1,})(.*)/); // カテゴリ別商品ページ var detail_res = ret.match(/\/products\/detail\.php\?(.*)product_id=(\d{1,})(.*)/); // 商品詳細ページ // 初期化 var rep_url = null; var rep_param = ''; if(cat_res){ // カテゴリ別商品ページ用URL変換処理 res_data = cat_res; if((typeof res_data[2] != "undefined") && res_data[2] && (typeof pattern['category_list'][res_data[2]] != "undefined") && pattern['category_list'][res_data[2]]){ rep_url = window.location.protocol + '//' + window.location.host + '/' + pattern['category_list'][res_data[2]] + '.php'; } } else if(detail_res){ // 商品詳細ページ用URL変換処理 res_data = detail_res; if((typeof res_data[2] != "undefined") && res_data[2] && (typeof pattern['products_category_list'][res_data[2]] != "undefined") && pattern['products_category_list'][res_data[2]]){ rep_url = window.location.protocol + '//' + window.location.host + '/' + pattern['products_category_list'][res_data[2]] + '_' + res_data[2] + '.php'; } } if(res_data && rep_url){ if((typeof res_data[1] != "undefined") && res_data[1]){ rep_param = '?' + res_data[1].slice(0, -1); } if((typeof res_data[3] != "undefined") && res_data[3]){ if(rep_param){ rep_param = rep_param + res_data[3]; }else{ rep_param = '?' + res_data[3]; } } if(rep_param){ rep_param = rep_param.replace('??','?'); rep_param = rep_param.replace('?&','?'); rep_param = rep_param.replace('&&','&'); } $(this).attr('href', rep_url + rep_param); } } }); });