I was wondering if it would be possible to redirect a url to another specific url that is got from a database? For example if www.mydomain.com/page was entered it would redirect to www.mydomain.com/folder/page and if www.mydomain.com/page2 was entered it would redirect to www.mydomain.com/folder/page2.
At the minute I just have redirects in my 404 page with this code:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$page= 'http://www.mydomain.com/page';
if ($url == $page){
header("HTTP/1.1 301 Moved Permanently");
header( 'Location: http://www.mydomain.com/folder/page' ) ;
}
?>
and I've done this with multiple other pages as well.
Thanks for any help!
解决方案
Sure
you have to first get the url from the database
then redirect it using php's header function
$result = mysql_query('SELECT * FROM `your_table` WHERE `token`= $token');
$row = mysql_fetch_assoc ( $result );
header("Location: page/{$row['url']}");
replace your_table with your table name that contains the redirection rules
however if your redirection rules always consist on adding /page before the url, then check the other answers