Jump to content

Redirect problem


manlio
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Thank you Marcus. I'm using code by Ryan so I was thinking was a good practice https://processwire.com/talk/topic/1716-integrating-a-member-visitor-login-form/?p=15919.

Anyway how I can  set in the right way the root in Processwire? Because also links point to localhost/profile instead of localhost/Processwire/profile

Thank you agian 

Link to comment
Share on other sites

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
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...