TopCoder
TopCoder

Reputation: 4296

Redirect with Mason 1.0

I am using Mason 1.0 and want to redirect the page to another URL.

Is there any way to redirect?

Alternatively...

I have written following code in dbhandler which is giving error, stating that $r is undefined. Can you please help.

$r->method('GET');
$r->headers_in->unset('Content-length');
$r->content_type('text/html');
$r->header_out('Location' => $newPageURL);
$m->abort(301);

I cannot use $m->redirect as it is not avalible to me.

I am referring to this link http://www.masonhq.com/htmlmason/wiki/FAQ:HTTPAndHTML on the section "How do I do an external redirect?"

Upvotes: 1

Views: 1605

Answers (2)

ExamplePerl
ExamplePerl

Reputation: 49

$r->status(302);
$r->headers_out()->add("Location", "http://google.com");
return 302;

Upvotes: 1

jeje
jeje

Reputation: 3211

Looks like $m->clear_buffer is missing before your first call.

It's required so it wipes out any response generated before you reach your redirection.

Upvotes: 0

Related Questions