ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Redirected template trouples

June 28, 2007 7:01pm

Subscribe [3]
  • #1 / Jun 28, 2007 7:01pm

    Jacob Fentress

    37 posts

    From time to time, I’ve had the need to move templates on my site (mainly to make urls simpler and make more sense). When doing so, I’ve desired to redirect from my old template to the new template, to avoid any problems from folks who have bookmarked a page or people coming from a search engine.

    To accomplish that, I’ve taken to placing the something like the following in the old template:

    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header('Location: <a href="http://website.com/new_template/{segment_3}">http://website.com/new_template/{segment_3}'</a>);
    ?>

    Of course, PHP is turned on (on input) for the old template in these cases.

    This has worked as expected, but it seems to have stopped working with my recent upgrade to 1.6.0 (I upgraded to the most recent build a hour ago to try and fix the problem). I also tried playing with my htaccess file to accomplish the same thing, but I can’t get it to work as expected (I also hide the index.php from my urls).

    Accessing the page from Omniweb says “Cannot Load Address: Bad Server Response”.

    Any insight into this or suggestions would be appreciated.

    Thanks in advance.

  • #2 / Jun 28, 2007 8:48pm

    Sue Crocker

    26054 posts

    Hi, Jacob.

    You need to add exit; to your code. Then it will work. I queried in Google for php header redirect and found the answer.

  • #3 / Jun 29, 2007 12:54am

    Jacob Fentress

    37 posts

    Sue, thanks for the response.

    Unfortunately, the addition of exit; doesn’t seem to be working for me. My above code seems to work just fine when run as a standard php page on my site (not through EE) - of course that page doesn’t have the {segment_3} stuff in it.

    So, I’m only having a problem with the redirect code when it lives inside a template.

    Any other ideas - or perhaps clarification on your suggestion. It’s completely possible I misunderstood what you were recommending.

  • #4 / Jun 29, 2007 12:57am

    Jacob Fentress

    37 posts

    As a note: when I add exit;, I no longer get the error in my brower, but the page is blank and it doesn’t redirect. Hmmm.

  • #5 / Jun 29, 2007 8:07pm

    Jacob Fentress

    37 posts

    Hey guys, I don’t mean to be a bother, but I noticed this in the change log for 1.6.0:

    Modified the sending of HTTP Headers because of a change in behavior in current versions of PHP

    I believe this may be the source of my new-found woes in 1.6. Could you elaborate on this change a little to help lead me towards a solution?

    Thanks.

  • #6 / Jun 29, 2007 8:14pm

    Derek Jones

    7561 posts

    That change only affected headers on EE output, not your use of header() PHP functions on your own, so that wouldn’t be it.  Do you have any .htaccess?  That error in Omniweb sounds suspiciously like it might be caught in a redirect loop.  Incidentally, you do need to exit; after issuing a header() redirect, otherwise EE will continue processing, including attempting to send its own headers at the end when output is sent to the browser.

  • #7 / Jun 29, 2007 8:24pm

    Jacob Fentress

    37 posts

    Ok, Ok… I’m a bit bashful to announce that everything is now working as it should.

    The exit; line that Sue recommended has helped - as I got it to work with it, and got it to break without. I’m still not sure why it didn’t work yesterday or why it worked weeks ago.

    I’m guessing my recent trouble should be attributed to something else entirely.

    Forgive me for going on about seemingly minor problem, and thanks for being patient with my posts as I figured it out.

    Thanks again, Sue, for you looking up about my problem and taking the time to offer a helpful suggestion, and thank you Derek for elaborating - more information is always appreciated. EE has an excellent support staff.

    Update - the reason the exit; code didn’t work yesterday - and gave me a blank page instead - is that when updated to the newer build of EE, I missed copying a ’ at the end of one of my few hacks. So there you have it… it was my own fault. I’m sorry. Let that go to show you kids that hacks are almost always more trouble than they are worth.

  • #8 / Jun 29, 2007 8:28pm

    Sue Crocker

    26054 posts

    No worries, Jacob. That’s what we’re here for.

    You might want to consider creating a HowTo entry for the wiki just in case you need it again. 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases