Alex Rivera | Logout

Faster redirect, PHP or htaccess?

Asked 2011-10-04T15:56:30.617
9

What is FASTER way to redirect a particular (specific) page, a PHP or htaccess? Considering that many different pages may need such redirect on a high traffic site. e.g. what is faster:

PHP (no database queries involved, just simple plain php redirect)

header("Location: /new.php",TRUE,301);

or

htaccess

redirect 301 old.php http://site.com/new.php
Edit
Report

1 Answer

3

If .htaccess is used at all, Apache will process it before any PHP processing begins. I haven't done the benchmarks on using one or the other, but when both are present, .htaccess will always be faster.

Also note that .htaccess redirect can be written using regex to apply to multiple old files, so less work on your end.

answered 2011-10-04T16:01:27.877

Your Answer