Home Page arrow Web Article arrow 对joomla创建的网站进行SEF

对joomla创建的网站进行SEF

文章分类 网络摘记 - Joomla相关 | 发布时间 Date:2008-06-18 | 浏览次数 View:6477

在不使用插件和不需要mod_rewrite支持的情况下,通过对includes/sef.php的修改可以实现joomla的SEF,这个不算是新东西,收录在这里做个参考,也希望给需要的朋友一个方便,使用效果可以参照yutheme.cn本站的链接。

1. 到后台开启SEF功能
2. 不要把htaccess.txt重命名为.htaccess
3. 打开includes/sef.php,找到
在joomla的512行有详细的英文注释,指导大家如何进行修改:
找到代码
return $mosConfig_live_site."/".$string;
然后用"//"注释掉,在下面增加一行代码
return $mosConfig_live_site."/index.php/".$string;
修改后刷新网站页面,你会发现网站中所有的URL已经发生变化,变成: http://www.***.com/index.php/component/link/5/6/32
这种形式了,如果点击后能够正常显示页面,那么便成功了!

如果连接不能正常访问也不要沮丧,稍作修改就可以了。将上面的代码做修改如下:

return $mosConfig_live_site."/index.php?/".$string;
修改后刷新网站页面,你会发现网站中所有的URL已经发生变化,变成: http://www..***.com/index.php?/component/link/5/6/32

这是joomla中原文的注释

// allows SEF without mod_rewrite                                允许在没有mod_rewrite的情况下进行SEF优化
// comment line below if you dont have mod_rewrite                如果没有mod_rewrite就注视掉下面的这行代码
//return $mosConfig_live_site .'/'. $string . $fragment;


return $mosConfig_live_site."/index.php/".$string . $fragment;        这是修改后的代码


// allows SEF without mod_rewrite                                允许在没有mod_rewrite的情况下进行SEF优化
// uncomment Line 512 and comment out Line 514                        去掉512行的注释符,并注释掉514行
// uncomment line below if you dont have mod_rewrite                如果没有mod_rewrite就去掉下面的注释符号
// return $mosConfig_live_site .'/index.php/'. $string . $fragment;
// If the above doesnt work - try uncommenting this line instead        如果上面的修改不起作用,试一下下面这行代码
 // return $mosConfig_live_site .'/index.php?/'. $string . $fragment;

sef化后, 结尾增加.html 的方法

(此方法来自autoit.cn,如果想查看更多JOOMLA技术文章,请去此站)

 /includes/sef.php

 将:

defined( '_VALID_MOS' ) or die( 'Restricted access' );

 替换为:

defined( '_VALID_MOS' ) or die( 'Restricted access' ); $_SERVER['REQUEST_URI']=str_replace(".html","",$_SERVER['REQUEST_URI']);

 将18行左右:

$url_array = explode('/', $_SERVER['REQUEST_URI']);

 替换为:

$url_array = explode('/', $_SERVER['REQUEST_URI']=str_replace(".html","",$_SERVER['REQUEST_URI']));

 搜索下行代码第一个出现的地方[约在513行左右]

// allows SEF without mod_rewrite

 在其上面增加

if(!strcasecmp(substr($string,-1),"/"))$string=substr($string,0,-1); if($string!="")$string.=".html";

ok. 这样,你的也就有了这个 .html 的尾巴了...

 

不一定适合所有的组件. 如果你刚好碰到了可能要用下面的样子来替换上面的两行:

if (!eregi("com_docman",$string)){ if(!strcasecmp(substr($string,-1),"/"))$string=substr($string,0,-1); if($string!="")$string.=".html"; }

注意: 上面代码里出现的 com_docman 就是在com_docman 里不加这个尾巴.你的看着改.

 

其实我用的是:

$string=substr($string,0,-1); $string.=".html";

都没加判断...因为我用的东西也不多,使用过程没发现异常

 Joomla相关 对joomla创建的网站进行SEF
Related Articles

网摘: Google书签 Yahoo书签 雅虎收藏夹 365Key网摘 新浪ViVi 百度收藏 天极网摘 diglog 和讯网摘 POCO网摘 YouNote网摘 博拉网 天下图摘 spurl blogmarks BlinkList reddit digg Del.icio.us QQ书签 推荐到鲜果

评论 (5)
12009-03-20 10:09
 
我说的就是在[B]不使用插件和不需要mod_rewrite支持[/B]的情况下进行SEF的,不信你试试
注册会员
 
yuyu
22009-03-19 11:06
 
开启SEF功能需要把htaccess.txt重命名为.htaccess  
,但你在第2步说不要把htaccess.txt重命名为.htaccess 那不是矛盾吗?看不明白啊。
访客
 
michael
32008-07-22 12:58
 
TO:大幅度飞 
后台 全站设定>>搜索引擎优化>>友好搜索引擎网址选“是”
注册会员
 
yuyu
42008-07-22 11:52
 
1. 到后台开启SEF功能  
 
这步怎么做啊
访客
 
大幅度飞
52008-06-28 03:05
 
不错
访客
 
easy

发表评论
  • 评论内容中的链接自动增加rel="nofollow",搜索引擎不会收录,请不要利用评论来做广告,此类话题将被删除。
  • rel="nofollow" in use - do not spam, do not advertise! un-related or spam comments will be deleted.
姓名:
评论:



验证码:* Code

 
下一篇 > 模版开发手册
TOP