Tags
PHP
Asked 2 years ago
30 Jun 2021
Views 383
Katlynn

Katlynn posted

301 or 302 Redirection With PHP

i am currently moving website to new domain and both domain is aviliable
so how can it be help in 301 or 302 Redirection With PHP
i am not sure what to use . for now user will see the new site pages with works in progress for some pages in new website
so how to do with 301 or 302 Redirection , i am using php as script
debugger

debugger
answered Jun 30 '21 00:00

you can use the header function at PHP code or .htaccess

put this code in the old website and suppose index.php moving redirect to another domain's index.html
then code will be in the old website in index.php

header('Location: www.example.com/index.html', true, 301);
exit;



it will move all traffic old to the new website
but if you have more pages and with a different link then you should use .htaccess and use a regular expressions to match more URL in once


RewriteEngine On
RewriteRule  ^index.php
http://www.newdomain.com/index.html  [R=301]


david

david
answered Jun 30 '21 00:00

301 means Moved Permanently



header('Location: www.example.com/index.html', true, 301);
exit;

302 means Moved temporary


header('Location: www.example.com/index.html', true, 302);
exit;
Post Answer