在 Joomla 1.5 中使用标准 SEF 我有如下链接:mysite.com/news/36-good-news-tooday
. 我需要从 url 中删除文章 ID 并获得如下内容:mysite.com/news/good-news-today
。
注意:这意味着我不想使用任何插件(如 HP 路由器等)我想编辑 Joomla 自己的 SEF。
UPD:终于我找到了决定。这是 router.php 的完整列表,您可以在components/com_content
<?php
/**
* @version $Id: router.php 14401 2010-01-26 14:10:00Z louis $
* @package Joomla
* @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
function ContentBuildRoute(&$query)
{
$segments = array();
$menu = &JSite::getMenu();
if (empty($query['Itemid'])) {
$menuItem = &$menu->getActive();
} else {
$menuItem = &$menu->getItem($query['Itemid']);
}
$mView = (empty($menuItem->query['view']))? null : $menuItem->query['view'];
$mCatid = (empty($menuItem->query['catid']))? null : $menuItem->query['catid'];
$mId = (empty($menuItem->query['id']))? null : $menuItem->query['id'];
if(isset($query['task'])) {
return $segments;
}
if(isset($query['view']))
{
$view = $query['view'];
if(empty($query['Itemid'])) {
$segments[] = $query['view'];
}
unset($query['view']);
};
if (($mView == 'article') and (isset($query['id'])) and ($mId == intval($query['id']))) {
unset($query['view']);
unset($query['catid']);
unset($query['id']);
}
if (isset($view) and ($view == 'section' && !empty($query['Itemid']))) {
if (($mView != 'section') or ($mView == 'section' and $mId != intval($query['id']))) {
$segments[] = 'section';
unset($query['Itemid']);
}
}
if (isset($view) and $view == 'category') {
if ($mId != intval($query['id']) || $mView != $view) {
$temp = explode(':',$query['id']);
if(count($temp) > 1)
{
$query['id'] = $temp[1];
}
$segments[] = $query['id'];
}
unset($query['id']);
}
if (isset($query['catid'])) {
if ((($view == 'article') and ($mView != 'category') and ($mView != 'article') and ($mCatid != intval($query['catid'])))) {
$temp = explode(':',$query['catid']);
if(count($temp) > 1)
{
$query['catid'] = $temp[1];
}
$segments[] = $query['catid'];
}
unset($query['catid']);
};
if(isset($query['id'])) {
if (empty($query['Itemid'])) {
$temp = explode(':',$query['id']);
if(count($temp) > 1)
{
$query['id'] = $temp[1];
}
$segments[] = $query['id'];
} else {
if (isset($menuItem->query['id'])) {
if($query['id'] != $mId) {
$temp = explode(':',$query['id']);
if(count($temp) > 1)
{
$query['id'] = $temp[1];
}
$segments[] = $query['id'];
}
} else {
$temp = explode(':',$query['id']);
if(count($temp) > 1)
{
$query['id'] = $temp[1];
}
$segments[] = $query['id'];
}
}
unset($query['id']);
};
if(isset($query['year'])) {
if(!empty($query['Itemid'])) {
$segments[] = $query['year'];
unset($query['year']);
}
};
if(isset($query['month'])) {
if(!empty($query['Itemid'])) {
$segments[] = $query['month'];
unset($query['month']);
}
};
if(isset($query['layout']))
{
if(!empty($query['Itemid']) && isset($menuItem->query['layout'])) {
if ($query['layout'] == $menuItem->query['layout']) {
unset($query['layout']);
}
} else {
if($query['layout'] == 'default') {
unset($query['layout']);
}
}
};
return $segments;
}
function ContentParseRoute($segments)
{
$vars = array();
$menu =& JSite::getMenu();
$item =& $menu->getActive();
$db =& JFactory::getDBO();
$count = count($segments);
if(!isset($item))
{
$vars['view'] = $segments[0];
$vars['id'] = $segments[$count - 1];
if($vars['view'] == 'article')
{
$query = 'SELECT id FROM #__content WHERE alias = '.$db->Quote($vars['id']);
} elseif($vars['view'] == 'category') {
$query = 'SELECT id FROM #__categories WHERE section > 0 && alias = '.$db->Quote($vars['id']);
}
$db->setQuery($query);
$vars['id'] = $db->loadResult();
return $vars;
}
switch($item->query['view'])
{
case 'section' :
{
if($count == 1) {
$vars['view'] = 'category';
if(isset($item->query['layout']) && $item->query['layout'] == 'blog') {
$vars['layout'] = 'blog';
}
}
if($count == 2) {
$vars['view'] = 'article';
$vars['catid'] = $segments[$count-2];
}
$vars['id'] = $segments[$count-1];
} break;
case 'category' :
{
$vars['id'] = $segments[$count-1];
$vars['view'] = 'article';
} break;
case 'frontpage' :
{
$vars['id'] = $segments[$count-1];
$vars['view'] = 'article';
} break;
case 'article' :
{
$vars['id'] = $segments[$count-1];
$vars['view'] = 'article';
} break;
case 'archive' :
{
if($count != 1)
{
$vars['year'] = $count >= 2 ? $segments[$count-2] : null;
$vars['month'] = $segments[$count-1];
$vars['view'] = 'archive';
} else {
$vars['id'] = $segments[$count-1];
$vars['view'] = 'article';
}
}
}
$alias = explode(':', $vars['id']);
if((int) $alias[0] > 0)
{
$vars['id'] = $alias[0];
} else {
if(count($alias) > 1)
{
$vars['id'] = $alias[0].'-'.$alias[1];
}
if($vars['view'] == 'article')
{
$query = 'SELECT id FROM #__content WHERE alias = '.$db->Quote($vars['id']);
} elseif($vars['view'] == 'category') {
$query = 'SELECT id FROM #__categories WHERE section > 0 && alias = '.$db->Quote($vars['id']);
}
$db->setQuery($query);
$vars['id'] = $db->loadResult();
}
return $vars;
}
我不是作者!路由器代码由Marvin Ryan修改。
这段代码在大多数情况下都能完美运行!但是我在使用 JoomFish 语言切换时遇到了一些问题。它有这样的链接,www.mysite.com/news/22
所以我只得到文章 ID,而不是文章别名。这个问题仍然存在!