Jump to content

How to redirect to page outside PW


OllieMackJames
 Share

Recommended Posts

How can I redirect to a page outside PW?

I have tried the following:

- I made a field called redirect with type=url

- I also made a redirect.php template with the following code:

<?php 
$session->redirect($redirect);
?>

Then I made a page called Log In that uses template redirect

I set the redirect field to : http://www.domain.com/desired-page-outside-pw.html

When I view the page I get this error:

The page isn't redirecting properly
          Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
 

Any ideas how to do this?

Link to comment
Share on other sites

Hi, i made quick test and redirecting outside PW working good.

For quick test put this code at begining of your home template.

$url = "http://www.google.com";
$session->redirect($url);
  • Like 2
Link to comment
Share on other sites

Could Apeisa's module be of help?

Thanks for the reply, tried that as follows:

I made a page /log-in/ so it appears in the menu

I redirected /log-in/ to http://www.domain.com/target-url.html

But it does not work, it now shows the pw page for /log-in/

Radek, thanks, have not tried your solution yet, do not see yet how to include this in the menu, but will try.

Hi, i made quick test and redirecting outside PW working good.

For quick test put this code at begining of your home template.

$url = "http://www.google.com";
$session->redirect($url);
Link to comment
Share on other sites

Thanks for the reply, tried that as follows:

I made a page /log-in/ so it appears in the menu

I redirected /log-in/ to http://www.domain.com/target-url.html

But it does not work, it now shows the pw page for /log-in/

This just means that everything worked as expected; Redirects module doesn't do redirect if PW page with that URL exists (it only does redirect when 404 is encountered), so when using it you shouldn't create matching page.. try removing it and redirect should work :)

How can I redirect to a page outside PW?

I have tried the following:

- I made a field called redirect with type=url

- I also made a redirect.php template with the following code:

<?php$session->redirect($redirect);?>
Then I made a page called Log In that uses template redirect

I set the redirect field to : http://www.domain.com/desired-page-outside-pw.html

When I view the page I get this error:

The page isn't redirecting properly          Firefox has detected that the server is redirecting the request for this address in a way that will never complete. 
Any ideas how to do this?

There's a slight problem in your code; it would seem that you're using (probably undefined) variable called $redirect instead of $page->redirect (redirect property of $page object, ie. the value of redirect field.) If your intention was to use value from field called "redirect", try this instead:

<?php
$session->redirect($page->redirect);
  • Like 3
Link to comment
Share on other sites

There's a slight problem in your code; it would seem that you're using (probably undefined) variable called $redirect instead of $page->redirect (redirect property of $page object, ie. the value of redirect field.) If your intention was to use value from field called "redirect", try this instead:

<?php
$session->redirect($page->redirect);

with the above approach of OllieMackJames, this is the solution I needed to link to an external page inside MarkupSimpleNavigation menu.

Thx!

Link to comment
Share on other sites

  • 3 weeks later...

Edit: somehow I overlooked, that teppo already found the exact same thing ages ago... Don't mind, I just have to (!) get something done with Typo3 and try to make it standable by surfing through the Processwire forums...



While directly linking to the URL in your menu is certainly the better idea, I think you just have a small error there:
 

How can I redirect to a page outside PW?
 
I have tried the following:
 
- I made a field called redirect with type=url
 
- I also made a redirect.php template with the following code:
 

<?php 
$session->redirect($redirect);
?>

 
Should have been:

<?php
$session->redirect($page->redirect);

 
I've been using this approach for quite a long time without any problems. It's nice if you want to provide a link to an external URL that may change over time.

  • Like 1
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...