Welcome Guest, Not a member yet? Register   Sign In
301 redirect to an external site [Solved]
#1

[eluser]ajitabhpandey[/eluser]
Hi,

The documentation for the redirect() function of URL Helper says that it is meant for redirection within site, but the application which I am writing have to redirect the URL to a another website using 301 redirect at some point in the code. How can I achieve that in CI? Is there a library function which I missed out in the documentation or I need to write one of my own? If later then any tips on what minimum headers needs to be set using Output class and then how do I send the headers to browser.

Thanks.
#2

[eluser]Clooner[/eluser]
Use the php function!
Code:
header('Location: http://www.yoursite.com', TRUE, 301);
exit(0);
#3

[eluser]danmontgomery[/eluser]
read the user guide.

Code:
// with 301 redirect
redirect('/article/13', 'location', 301);
#4

[eluser]ajitabhpandey[/eluser]
@Jeroen Schaftenaar, thanks this is working fine.

@noctrum, as per the docs the redirect() function in CI is for internal redirection only.
#5

[eluser]Stenna[/eluser]
301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. It's not that hard to implement and it should preserve ... Please refer to section titled 'How to Redirect with htaccess', if your site is hosted on a Linux Server and 'IIS Redirect', if your site is hosted on a Windows Server.

your post nise but not perfect so keep it up.

Thanks
------------------------
#6

[eluser]danmontgomery[/eluser]
[quote author="ajitabhpandey" date="1282154229"]@noctrum, as per the docs the redirect() function in CI is for internal redirection only.[/quote]

And if you try it, you'll see that it works normally if you provide an external url.

Code:
$this->load->helper('url');
redirect('http://www.google.com', 'location', 301);
#7

[eluser]Clooner[/eluser]
[quote author="ajitabhpandey" date="1282154229"]@Jeroen Schaftenaar, thanks this is working fine.

@noctrum, as per the docs the redirect() function in CI is for internal redirection only.[/quote]
Your welcome!

Noctrum's method would also work perfectly fine. CI will detect when there is a full url.
#8

[eluser]ajitabhpandey[/eluser]
@noctrum, thanks. I never tried external URL with that function. I think sometimes we can not trust the docs fully ;-)

@Stenna, I never wanted to use the .htaccess method of redirection as that is not the requirement of the application. I was looking for a CI way of doing this stuff and it turns out that the redirect function can do that.

Thanks all for participating in the discussion and coming up with suggestions.




Theme © iAndrew 2016 - Forum software by © MyBB