本帖最后由 紫衫木 于 2012-8-6 13:18 编辑
如果安装了Ultimate SEO URLs插件后,默认的产品目录URL形式是/目录名-c-目录ID.html,默认的重写规则是^(.)-c-(.).html$
但是这样的目录页URL似乎不是很好,因为我们知道目录页一般都是不带.html后缀的,而且目录页有PR,而页面很少有PR。这个也是Ultimate SEO URLs插件的不足之处。
其实我们可以自己修改Ultimate SEO URLs插件的源代码来达到这样的效果。
找到这个文件includes\classes\seo.url.php 然后找到function make_url 函数,修改为如下代码function make_url($page, $string, $anchor_type, $id, $extension = '.html', &$separator){
// Right now there is but one rewrite method since cName was dropped
// In the future there will be additional methods here in the switch
switch ( $this->attributes['SEO_REWRITE_TYPE'] ){
case 'Rewrite':
if($anchor_type=='cPath'){//主要就是添加了这个条件判断语句
return $this->reg_anchors[$anchor_type].$id .'/' . $string;///这里就是重写后的url形式,
}
return $string . $this->reg_anchors[$anchor_type] . $id . $extension;
break;
default:
break;
} # end switch
} # end function
修改完这个函数后,接下来找到$this->reg_anchors = array(
'products_id' => '-p-',
'cPath' => 'category/',///修改这里,我这里修改成category/,可以随便取一个名字,后面必须要带/
'manufacturers_id' => '-m-',
'pID' => '-pi-',
'products_id_review' => '-pr-',
'products_id_review_info' => '-pri-',
// News & Article Manager SEO support
'news_article_id' => '-a-',
'news_comments_article_id' => '-a-',
'news_dates' => '/',
'news_archive_dates' => '/archive/',
'news_rss_feed' => '/rss',
// Info Manager (Open Operations)
'info_manager_page_id' => '-i-',
// EZ-Pages SEO support
'id' => '-ezp-',
);
最后修改重写规则
打开根目录下的.htaccess文件,修改RewriteRule ^(.*)-c-(.*).html$ index\.php?main_page=index&cPath=$2&%{QUERY_STRING} [L]
为RewriteRule ^(.*)category/(.*)$ index\.php?main_page=index&cPath=$2&%{QUERY_STRING} [L]
这里的category/跟上面的’cPath’ => ‘category/’,是一致的。可以随便修改成你想要的样子。
好了,修改完之后可以试试看效果了。我这里的效果是这样的 域名/category/10/epi-leather
这样修改之后完全可以达到我们想要的效果了,但是有一个缺点就是这样修改后的URL是跟据目录的ID来获得目录页的信息,如果id号不变,后面目录名字变的话,这个页面内容是不会发生变化的。其实这个还是可以继续修改达到满意的效果,但是这里就不讲了,有能力的话就试试吧