最近遇到一个需求,做一个站的功能,只有在用户登录后才能看到网站的内容页面,如果用户未登录都跳转到注册登录页面,

下面把自己做的步骤写下来和大家分享一下:

1

在目录 /template/page/html 下新建一个文件,命令为:redirect.phtml.

redirect.phtml的内容为:

<?php
Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());  //save requested URL for later redirection
if(!Mage::getSingleton('customer/session')->isLoggedIn()) {  // if not logged in
    header("Status: 301");
  //  header('Location: '.Mage::helper('core/url')->getHomeUrl(customer/account/login)) ;  // send to the login page
   header('Location:'.Mage::getBaseUrl('web').'customer/account/login/'           ) ;
    exit;
}

?>

2

在page.xml写入代码

在文件page.xml中
  <default translate="label" module="page">
        <label>All Pages</label>
        <block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">

的后面加上代码:

<block type="page/html" name="auth-redirect" as="auth-redirect" template="page/html/auth-redirect.phtml"/>

3
在templatge/page
的文件

   
   
  • 1column.phtml
  • 2columns-left.phtml
  • 2columns-right.phtml
  • 3columns.phtml
的最前面加入代码 <?php echo $this->getChildHtml('auth-redirect'); ?> 4 现在是所有的页面都做跳转,但是登录和注册页面是不需要跳转的,所以要去掉 在layout文件下得custom.xml中 标签 <customer_account_login>和 <customer_account_create> 加入代码 <remove name="auth-redirect" /> 5 保存,刷新缓存,重新编译即可生效! 续~如果想首页可以访问,那么,在<cms_index_index>这个标签里加入代码
<remove name="auth-redirect" />
便可!
以上可以让每一个过来的用户都注册,缺点是阻碍了谷歌的抓取,不用seo推广的站才能用这种方式作站!