Jump to content

Recommended Posts

Posted

Hi, I'm try to develop a front end area and I have a little problem.

I'm on windows 8.1 and I use Wamp server.

When I use a redirect with short syntax like this

 $session->redirect('/profile/');

bring me to localhost/profile and doesn't find the page

If I use page syntax everything is working:

 $session->redirect($pages->get("/profile/")->url);

bring me to localhost/Processwire/profile

I would like to use the first easiest way. Can you help me?

Thanks

Posted

Hi, I'm try to develop a front end area and I have a little problem.

I'm on windows 8.1 and I use Wamp server.

When I use a redirect with short syntax like this

 $session->redirect('/profile/');

bring me to localhost/profile and doesn't find the page

If I use page syntax everything is working:

 $session->redirect($pages->get("/profile/")->url);

bring me to localhost/Processwire/profile

I would like to use the first easiest way. Can you help me?

Thanks

The first way may be shorter, but it isn't correct if you want to redirect to the page that has the path /profile/. In this case, the redirect() method does not expect a "ProcessWire Page Path", but simply does what you ask it to do, redirecting to [root]/profile. As if you would create a link:

<a href="/profile/">Foo</a>
  • Like 2
Posted

The problem is the folder and the relative urls. 

$session->redirect('/profile/');

This redirects to a page directly under root. For example: this code will redirect to http://manlio.com/profile/.

A ProcessWire url knows where the page is located (including if it's installed in a folder).

So:

$session->redirect($pages->get("/profile/")->url);

Will redirect to http://manlio.com/Processwire/profile/.

  • Like 2
Posted

The root url $config->urls->root  (including subfolders or if none it returns "/") 

So 

$session->redirect($config->urls->root . "profile/");
  • Like 1

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
  • Recently Browsing   0 members

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