user2536914
user2536914

Reputation: 45

redirecting site in php and htaccess, differences?

Are there any differences (for the google robots etc.) between this two codes?

PHP:

// 301 Moved Permanently
header("Location: /foo.php",TRUE,301);
exit;

and

.htaccess

RewriteRule ^site1.php$ http://www.example.pl/text.html [R=301,L]

Upvotes: 0

Views: 54

Answers (2)

Álvaro González
Álvaro González

Reputation: 146410

They both generate a Location HTTP header and a 301 status code and Google has no way to know what tools where used in the process. Your PHP version is missing the protocol prefix and hostname so it's technically invalid (as per the corresponding RFC) but it's a widespread misuse and all browsers do the right thing anyway. And code can be fixed anyway.

No idea about Apache but PHP performance tends to improve vastly on each major version. And of course your precise server resources and load will probably have a greater impact that most other factors. So I don't think it makes sense to as what's faster in such general terms. Given your server, run benchmarks and find your figures.

Also, if high performance is a must you can also consider skipping mod_rewrite and using something else such as mod_headers and its Header directive. Or dropping Apache and switching to e.g. nginx ;-)

Upvotes: 1

Hieu Le
Hieu Le

Reputation: 8415

There is no different in those redirect method except that if you use PHP to return 301 header, it's take some addition amount of time to execute PHP interpreter. While using .htaccess, the PHP interpreter will not be called.

Upvotes: 0

Related Questions