Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP header redirect 301 - what are the implications?

I have domain.com. If the user is logged in, it should load automatically domain.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:

  1. Since the search engines crawlers won't be logged in, they will always get domain.com/option-a - does it affect them that it has a 301 header?
  2. 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.
like image 488
Andres SK Avatar asked Sep 06 '11 18:09

Andres SK


People also ask

What is the purpose of a 301 redirect?

A 301 signals a permanent redirect from one URL to another, meaning all users that request an old URL will be automatically sent to a new URL. A 301 redirect passes all ranking power from the old URL to the new URL, and is most commonly used when a page has been permanently moved or removed from a website.

Is 301 redirect safe?

Never use 302 redirects or meta refresh redirects for permanent redirects. 302 redirects are for temporary moves, and Google recommends not to use meta refresh redirects at all if possible. So, if you have either of these on your site, you should aim to either remove them or replace with 301 redirects.

What is 301 redirect error?

The HyperText Transfer Protocol (HTTP) 301 Moved Permanently redirect status response code indicates that the requested resource has been definitively moved to the URL given by the Location headers. A browser redirects to the new URL and search engines update their links to the resource.


1 Answers

The 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 wisely ;-)

After the redirect put exit(); to stop the rest of the script to execute

header("HTTP/1.1 301 Moved Permanently");  header("Location: /option-a");  exit(); 
like image 158
Roel Veldhuizen Avatar answered Sep 17 '22 13:09

Roel Veldhuizen