用于重定向到 url 的 PHP 脚本 [英] PHP Script for redirecting to url
问题描述
我有 2 个网址,例如 http://www.abc.com 和 http://www.xyz.com.
i am having a 2 Urls like http://www.abc.com and http://www.xyz.com.
每当我输入 http://www.xyz.com="http://www.abc.com" rel="nofollow noreferrer">http://www.abc.com 在浏览器中.
I am trying to redirect to http://www.xyz.com whenever i type http://www.abc.com in the browser.
当用户输入 http://www.abc.com/index.php?option=com_content&view=article&id=46&Itemid=55 类似这样的东西,即.abc.com 旁边的任何查询,然后我试图重定向到 http://www.xyz.com/index.php?option=com_content&view=article&id=46&Itemid=55.
And also when the user types http://www.abc.com/index.php?option=com_content&view=article&id=46&Itemid=55 something like this ie. any query next to abc.com then i am trying to redirect to http://www.xyz.com/index.php?option=com_content&view=article&id=46&Itemid=55.
如何在 PHP 中执行此操作...请帮助我...
how to do this in Php... Please help me..
我在模板文件中用 php 编写了一个脚本以重定向为
i wrote a script in php in my template file to redirect as
<?php
if(curPageURL()=="http://localhost/joomla/Joomla_1.5.7/"){
header("Location: http://localhost/joomla/Joomla_1.5.7copy/");
}
// else if(curPageURL()=="http://localhost/joomla/Joomla_1.5.7/"){}
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
在 else 中,如果我试图检查 http://localhost/joomla/Joomla_1.5.7/
是否在 url 旁边有任何查询,例如 http://localhost/joomla/Joomla_1.5.7/index.php?option=com_content&view=section&layout=blog&id=3&Itemid=55
In the else if i am trying to check if the http://localhost/joomla/Joomla_1.5.7/
has any queries next to the url like http://localhost/joomla/Joomla_1.5.7/index.php?option=com_content&view=section&layout=blog&id=3&Itemid=55
这样我就必须在它旁边进行查询并将其附加到http://localhost/joomla/Joomla_1.5.7copy/index.php?option=com_content&view=section&layout=blog&id=3&Itemid=55
..
so that i have to take the query next to it and to attach the same to
http://localhost/joomla/Joomla_1.5.7copy/index.php?option=com_content&view=section&layout=blog&id=3&Itemid=55
..
推荐答案
use Header("Location: http://www.xyz.com")
但是使用 .htaccess 可以实现更好的重定向,请参阅http://corz.org/serv/tricks/htaccess.php 了解一些信息关于那个.
use Header("Location: http://wwww.xyz.com")
however better redirection is done using .htaccess see http://corz.org/serv/tricks/htaccess.php for some information about that.
这篇关于用于重定向到 url 的 PHP 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!