21288 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1859 Views |
-
Redirect with header("Location: ...")

3 December 2009 at 1:38am Last edited: 3 December 2009 1:40am
hello all,
i would like to do a redirect to a certain domain. I tried to use the php funtion header("Location: http://www.mydomain.com");
i thought i could edit this in the file main.php at line 63:
if(!headers_sent()) header("Location: http://www.mydomain.com; Content-type: text/html; charset=\"utf-8\"");
but nothing changes.
do you know the right place to change the header location?greetz,
florian -
Re: Redirect with header("Location: ...")

3 December 2009 at 5:15am
Have you thought about using a RedirectorPage?
-
Re: Redirect with header("Location: ...")

3 December 2009 at 5:46am Last edited: 3 December 2009 5:48am
I've used that many times, but you have to be sure no other output is been made.
reading http://php.net/manual/en/function.headers-sent.php it seems that every example ends with an 'exit' statment to ensure that nothing else is written afterwards. Also I have only used a plain url there have you tried that too?
header('Location: http://www.example.com/');
Lastly I agree with above poster, have you tried:
Director::redirect('http://www.example.com/');
-
Re: Redirect with header("Location: ...")

3 December 2009 at 8:53am Last edited: 3 December 2009 8:55am
> i thought i could edit this in the file main.php at line 63:
The very last thing you should do is modify core files like main.php. That just leads to grief.
> it seems that every example ends with an 'exit' statment to ensure that nothing else is written afterwards.
exit(); prevents further code execution, so don't use it after Director::redirect
As the other posters have said, use a RedirectorPage, or a method in your controller that uses Director::redirect.
This has the following effect:
1. Sets the correct Location header and HTTP code
2. Provides a suitable html output for browsers that refuse to respect the redirection (or even are just a bit slow about it - it will says "Redirecting to..."
3. Additionally adds meta refresh and javascript redirect just to be sure.
-
Re: Redirect with header("Location: ...")

3 December 2009 at 9:56pm
hello together,
i forget to say what i exactly want to do. i have serveral domains linking to the same target / directory. I´ve read that google doesn´t like it to find the same content for different domains. So i want to specify a main domain and the other domains should be redirected to the main domain.
If somebody arrives at otherdomain.com/home he should be redirected to maindomain.com/home.
bye and thanks,
florian -
Re: Redirect with header("Location: ...")

3 December 2009 at 11:03pm
If you're trying to redirect multiple domains to one, then you really shouldn't use the Location header.
The Location header sends a 302 redirect, not a 301 (what google wants) and it's also hitting PHP for no reason at all.
You can easily set a 301 redirect in the .htaccess or in your servers control panel using domain pointing.
Something like this in your .htaccess should work:
RewriteCond %{QUERY_STRING} ^id=13$
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]
src: http://www.tamingthebeast.net/articles3/spiders-301-redirect.htmOr in DirectAdmin control panel you can set domain pointers so that lots of domains point to one domain - just add a pointer and uncheck the 'create alias' box. I'm not sure about cPanel or others, but i'm sure it is possible.
-
Re: Redirect with header("Location: ...")

26 December 2009 at 6:04am
hello,
redirecting via htaccess worked fine. for each domain i added these two lines at the top of the htaccess file:
RewriteCond %{HTTP_Host} ^(www\.)?otherdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.maindomain.com/$1 [L,R=301]greetz,
flo
| 1859 Views | ||
|
Page:
1
|
Go to Top |





