- This topic is empty.
-
AuthorPosts
-
September 6, 2011 at 6:49 am #10207andres-skParticipant
I have
example.com
. If the user is logged in, it should load automaticallyexample.com/option-X
where X is a predefined choice of the user.So, I do this at the top of
index.php
:header("Location: /option-X");
But, if the user is not logged in, I just choose automatically the first option like this:
header("HTTP/1.1 301 Moved Permanently"); header("Location: /option-a");
So, I have two questions regarding the implications of doing so:
- Since the search engines crawlers won’t be logged in, they will always get
example.com/option-a
– does it affect them that it has a 301 header? - What could be the server cpu load of doing those redirects? I don’t know how to make a test out of it. The current site (which has no redirects) has about 100k daily visits.
September 6, 2011 at 6:53 am #10209genesisParticipantMake sure you
die()
after your redirection, and make sure you do your redirect AS SOON AS POSSIBLE while your script executes. It makes sure that no more database queries (if some) are not wasted for nothing. That’s the one tip I can give youFor search engines, 301 is the best response code
September 6, 2011 at 6:53 am #10208profitphpParticipantSearch engines like 301 redirects better than a 404 or some other type of client side redirect, no worries there.
CPU usage will be minimal, if you want to save even more cycles you could try and handle the redirect in apache using htaccess, then php won’t even have to get involved. If you want to load test a server, you can use ab which comes with apache, or httperf if you are looking for a more robust testing tool.
September 6, 2011 at 6:57 am #10212roel-veldhuizenParticipantThe effect of the 301 would be that the search engines will index
/option-a
instead of/option-x
. Which is probably a good thing since/option-x
is not reachable for the search index and thus could have a positive effect on the index. Only if you use this wiselyAfter the redirect put
exit();
to stop the rest of the script to executeheader("HTTP/1.1 301 Moved Permanently"); header("Location: /option-a"); exit();
February 14, 2017 at 6:37 am #10210the_nutsParticipantJust a tip: using http_response_code is much easier to remember than writing the full header:
http_response_code(301); header('Location: /option-a'); exit;
May 4, 2017 at 12:56 pm #10211gary-samadParticipantThis is better:
<?php //* Permanently redirect page header("Location: new_page.php",TRUE,301); ?>
Just one call including code 301. Also notice the relative path to the file in the same directory (not “/dir/dir/new_page.php”, etc.), which all modern browsers seem to support.
I think this is valid since PHP 5.1.2, possibly earlier.
- Since the search engines crawlers won’t be logged in, they will always get
-
AuthorPosts
- You must be logged in to reply to this topic.