Jump to content

Session redirect problem


Kay Lohn
 Share

Recommended Posts

Hi,

I have a checkbox field called 'blocked' on pages using 'my-page-template' which is used to check if the page is blocked for 'guest' users.

Whenever those pages are accessed by guests then a simple check in the template file would redirect them to another page.

I have a page named 'blocked' using template 'blocked-page' to which the guests are redirected.

The 'my-page-template.php' has the code at top.

<?php if ($page->blocked == 1 && $user->isGuest()) {
    $session->redirect($pages->get('/blocked/')->url);
} ?>

<h1>Welcome</h1>
<p>This is my website</p>

Now, when a 'blocked' page is accessed the redirect goes straight to homepage.

In Chrome/Firefox Developer tools > Network the output/headers are as follows:

http://mysite.com/pages/somepage > GET > 301 > Initiator: Other

http://mysite.com/pages/somepage > GET > 302 > Initiator: http://mysite.com/pages/somepage

http://mysite.com/blocked > GET > 302  >  Initiator: http://mysite.com/blocked

The page redirects to http://mysite.com/ instead of http://mysite.com/blocked

The 'blocked-page' template does not have any redirect code. Content below:

<?php
echo '<h1>This page is blocked</h2>;
?>

What am I missing? Would deeply appreciate some help/ pointers. Thanks.

Link to comment
Share on other sites

UPDATE:

Fortunately, found out the reason.

The module 'MaintenanceMode' was the culprit. The pages worked as expected once the module was uninstalled.

To double check I re-installed the module again and same problem reappeared. On further investigation the redirect in 'MaintenanceMode' module was set to the 'blocked' page which caused the problem which when changed to some other page, the 'blocked' pages started to redirect as expected.

UPDATE:

Unfortunately, I had to uninstall the module for the reason that the page I set as 'blocked' would redirect to home when accessed directly, something which I do not want to happen. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...