【问题标题】:Variable php redirect based on url基于url的可变php重定向
【发布时间】:2017-04-15 12:11:24
【问题描述】:

我正在创建一个 index.php 文件,用于将所有网站重定向到特定主机 我想创建一个小 php 脚本,它可以根据特定的过滤器读取 url 和重定向。

例如: 如果 url = (everything).domain1.com 重定向到 default1.php 如果 url = (everything).domain2.com 重定向到 default2.php 在所有其他情况下,不喜欢 default3.php 的第一个或第二个重定向

这可以通过 php 实现吗?我必须使用 $_SERVER['HTTP_HOST'] 还是可以使用其他方法?

【问题讨论】:

  • 对于该任务,在.htaccess 中使用 RewriteCond 会更好
  • 是的,就像以前的评论一样,在 htaccess 加载类似这样的问题时这样做
  • 是的,我知道,但我不能使用 .htaccess
  • 为什么不能用?如果您有 ftp 访问权限,则可以使用它
  • 如果我使用 .htaccess 我可以在文件中写什么?

标签: php redirect http-redirect


【解决方案1】:

我解决了:

    <?php 
$domain = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
if (strpos($domain,'domain-name.com') == true) {
    header('location: /index2.php');
    exit();
} else {
    header('location: /index3.php');
}
?>

但不重定向...

【讨论】:

    猜你喜欢
    • 2011-06-23
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    相关资源
    最近更新 更多