I have changed my blog url. (I know .htaccess can do this)
RewriteEngine on
RewriteRule (.*) http://my-new-website.com/$1 [R=301]
but I can't use .htaccess now (personal reasons.. I can use only PHP now)
I want to use a PHP code to do that.
I want to redirect
http://my-old-website.com/v/test/new.html
To
http://my-new-website.com/v/test/new.html
I have searched a lot online, and looked for more similar questions on stackoverflow, but I didn't find any question like this
you can do it with setting the Location header. The following will add the given $_GET
parameters to and append them to the URL too:
$newUrl = "http://my-new-website.com/";
$currentPage = $_SERVER['PHP_SELF'];
//building the querystrging (if some GET variables where set):
$queryString = "";
if(count($_GET)) > 0) {
$queryString = "?" . http_build_query($_GET);
}
//set the header to redirect:
header('Location:'.$newUrl.$currentPage.$queryString);
ie: redirects http://example.com/v/file1.php?key1=val1&key2=val2
to http://my-new-website.com/v/file1.php?key1=val1&key2=val2
PHP has the header function to set custom headers. All you have to do is set the 'refresh' to a different page.
header('Refresh:10;url=newwebsite.php' . $_SERVER['REQUEST_URI']);
Just use a Location
header.
header('Location: http://my-new-website.com' . $_SERVER['REQUEST_URI']);
header('Content-Type: text/html');
die('I have moved to my-new-website.com'); // for ancient browsers