Joomla 3.3中具有用户名的URL

时间:2014-09-23 10:38:40

标签: php .htaccess joomla url-redirection

我正在寻找使用用户名显示网址的解决方案。我正在使用Joomla 3.3.0稳定版。

实施例。 SITE_URL / userp-用户名

我尝试使用.htaccess解决这个问题,并遵循我用于核心PHP网站的以下规则。

RewriteRule ^userp-([a-zA-Z0-9-_]+)/?$ site_url/index.php?option ... er_name=$1 [R=301,L]

当我点击例如http://sitename.com/userp-vishal07的网址时,它会执行我要为此网址调用的代码并正确显示结果。但是网址不会保持原样并变为http://vicciivital.com/index.php/en/component/users/profile?layout=view_profile&user_name=vishal07

我无法理解Joomla重定向的工作原理。如果我在这里犯了任何错误,请纠正我。

1 个答案:

答案 0 :(得分:1)

由于原因,我从未理解com_users路由器不会路由任何配置文件,除了用户自己的配置文件。

/**
 * Method to get a route configuration for the profile view.
 *
 * @return  mixed   Integer menu id on success, null on failure.
 * @since   1.6
 */
public static function getProfileRoute()
{
    // Get the items.
    $items  = self::getItems();
    $itemid = null;

    // Search for a suitable menu id.
    //Menu link can only go to users own profile.

    foreach ($items as $item)
    {
        if (isset($item->query['view']) && $item->query['view'] === 'profile')
        {
            $itemid = $item->id;
            break;
        }

    }
    return $itemid;
}

您需要做的是扩展此方法以处理每个人的个人资料。只需确保处理存在与用户别名具有相同别名的内容项或标记的情况。

通常,最简单的解决方法是使用com_contact作为配置文件。打开联系人创建者插件将自动为新用户创建联系人,联系人可以显示任何来自个人资料插件的内容。此外,它还可以显示用户的文章,然后您还可以根据需要为其他内容添加插件。对我而言,它总是比使用com_users配置文件好得多。