【问题标题】:Create redirect page with template tags included for single.php使用包含 single.php 的模板标签创建重定向页面
【发布时间】:2016-02-26 20:49:30
【问题描述】:

我想让每个访问的单个页面首先重定向到具有原始目标帖子永久链接的 template.php 页面,例如 AdFly 缩短网址服务

目前它使用PHP header() Function 工作。但我不知道如何让原始源页面永久链接包含在 template.php 中

<?php
 header("HTTP/1.1 301 Moved Permanently");
 header("Location: http://www.yournewwebsite.com/template.php");
?>

【问题讨论】:

  • 例如,如果我转到http://google.com,您想重定向到htttp://yourwebsite.com/template.php,那么它会将我重定向到google?
  • @KayVan blog.com/post_id=14 重定向到 blog.com/page.php,其中包含指向 blog.com/post_id=14 的链接

标签: php http-redirect


【解决方案1】:

您可以将链接作为参数传递给位置。

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://example.com/template.php?website=" . $_SERVER['REQUEST_URI']);

在您的 template.php 中,只需执行 $_GET['website'] 即可检索参数中传递的 url。

【讨论】:

    猜你喜欢
    • 2010-10-06
    • 2020-11-08
    • 2013-10-17
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 2016-09-08
    相关资源
    最近更新 更多