通过mysql数据库重定向多个网址? [英] Redirect multiple urls through mysql database?

查看:221
本文介绍了通过mysql数据库重定向多个网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想,如果有可能到一个URL重定向到正在从数据库中得到了另一种特定的网址是什么?例如,如果www.mydomain.com/page被输入会重定向到www.mydomain.com/folder/page~~V如果www.mydomain.com/page2被输入会重定向到www.mydomain.com/folder/page2~~V。

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.

目前一刻起,我只是重定向我404页与此code:

At the minute I just have redirects in my 404 page with this code:

<?php
$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.

感谢您的帮助!

推荐答案

确定

您必须首先从数据库中获取
网址 然后使用PHP的头功能

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']}");

替换 your_table 与包含重定向规则你的表名

replace your_table with your table name that contains the redirection rules

然而,如果你的重定向规则总是由上加入 /页的URL,然后,再检查其他答案

however if your redirection rules always consist on adding /page before the url, then check the other answers

这篇关于通过mysql数据库重定向多个网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆