2012-08-14 71 views
1

我激活了SEO友好的URL。基本上我的应用中的网址如下所示: http://x.com/enhttp://x.com/en/galleryjoomla禁止直接访问组件和模块

从我的应用程序没有链接,比方说,在com_users上。但用户仍然可以使用以下URL之一打开它:http://x.com/component/usershttp://x.com/?option=com_banners

我阻断第一个与此:

RewriteCond %{REQUEST_URI} /component/ [NC] 
RewriteRule ^.*$ - [F,L] 

如何可以阻止第二(选项= com_users?)?

我明白,这种行为可能是Joomla的默认和预期,但我只是想给你一个例子。

当我允许只有注册用户访问我的所有页面时,他们仍然可以访问组件。在Joomla管理的同时,没有阅读许可。最后,用户获取模板页面或某些数据(如果它是公开的),例如com_content的文章。和问题:如何在这种情况下提高403或至少重定向到/?

更新: 我需要阻止/用户视图=登记,复位提醒和配置文件?。我需要将任何错误重定向到登录页面。无论是整个Joomla组件还是视图,任务等都无所谓。

回答

1

我写我自己的插件来处理所有案件和重定向任何不便的情况下,到登录页面(/登录)。由于不方便,我的意思是任何直接访问Joomla中的任何组件,或者403或404,而不是500.现在,我的应用程序很适合只接受以下URL:/ login,/ home,/ gallery,/ gallery/album /任何和其他几个人。直接访问是完全禁止的,但是,用户不能使用URL参数(如?option=com_users)或/component/路径。

此方法不适用于关闭SEO网址。

<?php // no direct access 
defined('_JEXEC') or die('Restricted access'); 

jimport('joomla.event.plugin'); 

class plgSystemComontrol extends JPlugin { 

    function plgSystemComcontrol(& $subject, $config) { 
     parent::__construct($subject, $config); 
    } 

    function onAfterRoute() { 
     // get plugin parameters 
     $com_redirect_url = $this->params->def('com_redirect_url', 'index.php?option=com_user&view=login'); 
     $com_debug = $this->params->def('com_debug', '0'); 
     $com_message = $this->params->def('com_message', ''); 

     // get option, view, task .. 
     $mainframe = JFactory::getApplication(); 
     $option = JRequest::getCmd('option'); 
     $view = JRequest::getCmd('view'); 
     $task = JRequest::getCmd('task'); 

     // get current URL 
     $uri = JFactory::getURI(); 
     $url = $uri->toString(); 
     $u_host = $uri->getHost(); 
     $u_path = $uri->getPath(); 
     $path = substr($url, strlen(JURI::root())); 

     // get user permissions 
     $groupsUserIsIn = JAccess::getGroupsByUser(JFactory::getUser()->id); 
     $user_type = implode(" ",$groupsUserIsIn); 
     $group_sum = array_sum($groupsUserIsIn); 

     if ($com_debug == '1') { 
      $mainframe->enqueueMessage('--------------------------------'); 
      $mainframe->enqueueMessage('$option = '.$option); 
      $mainframe->enqueueMessage('$view = '.$view); 
      $mainframe->enqueueMessage('$task = '.$task); 
      $mainframe->enqueueMessage('$url = '.$url); 
      $mainframe->enqueueMessage('$path = '.$path); 
     } 

     if (strpos($path, 'administrator') === 0) { 
      return; 
     } 

     // set default redirect page 
     $redirectPage = ($group_sum > 1) ? 'index.php' : 'index.php/login'; 
     $directAccess = strpos($path, 'component') !== false || strpos($path, 'option') !== false; 

     // allow login page only 
     if ($option == 'com_users') { 
      if (($view == 'login' || empty($view) || $task == 'user.login' || $task == 'user.logout') && !$directAccess) { // $view == 'default' 
       return; 
      } else { 
       $mainframe->redirect($redirectPage, $directAccess ? 'Direct access to components forbidden' : 'Login/logout is enabled only'); 
       //JError::raiseError(403, JText::_('Forbidden')); 
       //return; 
      } 
     } 

     // deny direct access to components 
     if ($directAccess) { 
      $mainframe->redirect($redirectPage, 'Direct access to components forbidden'); 
      //JError::raiseError(401, JText::_('/component/')); 
     } 

     // get usertype to see if logged-in 
     // $user =& JFactory::getUser(); 
     // $user_type = $user->get('usertype'); 
     $groupsUserIsIn = JAccess::getGroupsByUser(JFactory::getUser()->id); 
     $user_type = implode(" ",$groupsUserIsIn); 
     $group_sum = array_sum($groupsUserIsIn); 
     if ($group_sum > '1') { 
      return ; 
     } 

     //if user logged-in, then return from function 
     if (empty($option)) { 
      return; 
     } 

     $mainframe->redirect($com_redirect_url, $com_message); 

     return; 
    } 
} 
?> 

我希望这将有助于了解如何执行一些自定义重定向并禁用对组件的直接访问。

1

我会走另一条路,并使用rel = canonical来实现此目的。

这是一种更简单/更好的做事方式,因为标签会出现在所有的“页面版本”中,而且您不需要设置许多特定于案例的规则或携带重启重定向文件......

这只是一个插件,可以帮助您进行canoniczlization。

http://extensions.joomla.org/extensions/site-management/seo-a-metadata/meta-data/11038?qh=YTo0OntpOjA7czo5OiJjYW5vbmljYWwiO2k6MTtzOjExOiInY2Fub25pY2FsJyI7aToyO3M6MTI6IidjYW5vbmljYWwnLiI7aTozO3M6NToiY2Fub24iO30%3D

+0

感谢您的回答。我没有尝试这种扩展,因为它似乎是我的需求比任何扩展可能提供的更自定义。我已经写了我自己的插件。我会用我自己的答案分享代码。 – ruruskyi 2012-08-31 13:03:07

+0

做得很好。 :) – 2012-09-02 09:13:00