Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between PHP and .htaccess redirect

Is there a difference between php header redirect and .htaccess redirect by the SEO of the site?

like image 238
Novinite Avatar asked Feb 19 '26 08:02

Novinite


1 Answers

Probably not - depends how you're doing your redirection.

In PHP:

header("Location: http://www.example.com/"); /* Redirect browser, emits 302 */

If you want to emit a 301, use:

header("Location: http://www.example.com/", true, 301);

More in the PHP documentation.

If you're doing this in your .htaccess:

Redirect 302 /PATH_TO_REDIRECT http://www.example.com/

then that'll emit a 302 too.

Again, making it emit a 301 is straightforward:

Redirect 301 /PATH_TO_REDIRECT http://www.example.com/

In general, for SEO, just do what makes sense. If something's moved permanently use 301, if something's moved temporarily (e.g. during a temporary reshuffle) use 302 (take a look at the response code definitions).

like image 161
Dominic Rodger Avatar answered Feb 20 '26 20:02

Dominic Rodger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!