R
R
Ressive2016-05-07 09:38:02
PHP
Ressive, 2016-05-07 09:38:02

301 redirect to php (wordpress)?

1. You need to make a lot of redirects to php, I found this code on the net
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.ru/newdir/newpage.htm");
exit();
?>
but I don't understand where to set the old url here.
2. Will a lot of redirects through .htaccess slow down the performance of the site?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
landergate, 2016-05-07
@landergate

  1. You don't need to set the old URL, because you are transferring users to some new URL. A 301 header with a link to redirect to will be enough to redirect the user's browser. It is assumed that this script lies along the path from where you will redirect users.
  2. Redirects, by themselves, will not noticeably slow down the performance of the site. The overhead is the use of the file .htaccess, instead of taking these parameters into the vhost config, which would be in Apache's memory all the time. File .htaccess pulls the disk every time the user connects.
    If there are really a lot of redirects directly (subjectively - up to a hundred or more), then option a) move the logic of redirects to the Apache vhost so that it is in memory, and not loaded with each visit; b) if there is nginx before Apache, it is better, of course, to transfer the redirection logic to it.

I
Ilya Voropaev, 2016-05-07
@SV0L0Ch

Alternatively, you can check the old URL directly in the code and call the transition according to the condition.
Something like

if($_SERVER['REQUEST_URI'] == '/oldurl/'){
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.newdomain.ru/newdir/newpage.htm");
    exit();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question