Menu

How to disable Chrome info bars in Codeception Acceptance tests?

How to continue script execution in background in PHP?

How to create permanent redirect in PHP?

php http header

Often we need to instruct browser that the URL has been moved to another location. This can be done in PHP by sending proper HTTP headers with header function. The very first example in PHP documentation shows redirect example, however by default this is treated as temporary redirection. This means that browser will check this every time, and also crawling bots might index old URL. In most cases we want to have redirection permanent. To do this, we need to send 301 HTTP code along with redirect statement. Also to ensure finishing of script execution, it is good to add exit instruction.

Redirect Permanent Example

<?php
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://meno.pro/');
exit;