Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建一个基于查询字符串或use.htaccess重定向的PHP页面_Php_Wordpress_.htaccess_Redirect - Fatal编程技术网

创建一个基于查询字符串或use.htaccess重定向的PHP页面

创建一个基于查询字符串或use.htaccess重定向的PHP页面,php,wordpress,.htaccess,redirect,Php,Wordpress,.htaccess,Redirect,我买了gravity forms wordpress插件,但遇到了一个问题,它无法根据用户的输入将用户重定向到特定的URL。然而,一位开发人员告诉我,它具有重定向到页面并根据输入导入查询字符串的功能。我需要做的就是在页面上使用PHP根据查询字符串重定向到另一个url 我已经在我的wordpress站点上创建了一个页面/formsubmitredirect,它根据用户输入成功地从链接/formsubmitredirect?否或/formsubmitredirect?是的末尾拉入查询字符串 如何根据

我买了gravity forms wordpress插件,但遇到了一个问题,它无法根据用户的输入将用户重定向到特定的URL。然而,一位开发人员告诉我,它具有重定向到页面并根据输入导入查询字符串的功能。我需要做的就是在页面上使用PHP根据查询字符串重定向到另一个url

我已经在我的wordpress站点上创建了一个页面/formsubmitredirect,它根据用户输入成功地从链接/formsubmitredirect?否/formsubmitredirect?是的末尾拉入查询字符串

如何根据这些查询字符串重定向此页面?


谢谢

在进行任何输出之前,请更改位置标题:

<?
header('Location: newloc.php'); // change to your liking

在进行任何输出之前,请更改位置标题:

<?
header('Location: newloc.php'); // change to your liking

查询字符串位于
$\u GET()
数组中,因此您可以执行以下操作-

if($_GET['formsubmitredirect '] == 'yes') {
   header("Location: newpage");
   exit();
} else {
   header("Location: somewhereelse");
   exit();
}

查询字符串位于
$\u GET()
数组中,因此可以执行以下操作-

if($_GET['formsubmitredirect '] == 'yes') {
   header("Location: newpage");
   exit();
} else {
   header("Location: somewhereelse");
   exit();
}

问题的答案取决于如何获取查询字符串。您是在页面模板中还是在短代码函数中执行此操作

如果其中一个是真的,主要问题是如果在加载包含代码的页面之前已经将标题加载到html中,则php会抱怨标题已经发送到浏览器,而不会执行重定向

根据我使用wordpress的经验,最好的选择是在wordpress加载任何模板之前,挂接到template_redirect操作,检查那里的查询变量并重定向。例如:

function my_redirect(){
    if(isset($_GET["yourvariable"]) && !empty($_GET["yourvariable"])){
        do your redirect here with wp_redirect()
        exit; //prevent wordpress continuing to load templates
    }
}
add_action("template_redirect","my_redirect");

问题的答案取决于如何获取查询字符串。您是在页面模板中还是在短代码函数中执行此操作

如果其中一个是真的,主要问题是如果在加载包含代码的页面之前已经将标题加载到html中,则php会抱怨标题已经发送到浏览器,而不会执行重定向

根据我使用wordpress的经验,最好的选择是在wordpress加载任何模板之前,挂接到template_redirect操作,检查那里的查询变量并重定向。例如:

function my_redirect(){
    if(isset($_GET["yourvariable"]) && !empty($_GET["yourvariable"])){
        do your redirect here with wp_redirect()
        exit; //prevent wordpress continuing to load templates
    }
}
add_action("template_redirect","my_redirect");
你可以用

$\u服务器['QUERY\u STRING']
获取当前查询字符串,并可以使用if条件轻松重定向页面…

您可以使用


$\u服务器['QUERY\u STRING']
要获取当前查询字符串,并可以使用if条件轻松重定向页面…

您可以根据get参数使用开关

switch ($_GET['location']) {
    case 'index':
        header("Location: index.php");
        break;
    case 'news':
        header("Location: news.php");
        break;
    default:
        header("Location: home.php");
        break;
}

现在,您可以通过使用page.php?location=index触发此开关,您可以根据GET参数使用开关

switch ($_GET['location']) {
    case 'index':
        header("Location: index.php");
        break;
    case 'news':
        header("Location: news.php");
        break;
    default:
        header("Location: home.php");
        break;
}

现在,您只需使用page.php?location=index来触发此开关即可。您好,谢谢您的回复,我应该将此代码放在我的wordpress站点的何处?通常放在functions.php或插件中。这会产生一个错误:无法修改标题信息-标题已发送。谢谢您的回复,我应该把这些代码放在我的wordpress站点的什么地方?通常在functions.php或插件中。这会产生一个错误:无法修改标题信息-标题已经发送