【问题标题】:.htaccess: Want query string added to 301 Redirect to same url.htaccess:希望将查询字符串添加到 301 重定向到相同的 url
【发布时间】:2013-06-24 15:04:47
【问题描述】:

示例:当有人访问此网址时

http://example.com/site/register

我希望自动添加此查询字符串:

http://example.com/site/register?destination=thankyou

我在 .htaccess 文件中尝试了以下内容:

重定向 301 /site/register /site/register?destination=thankyou

但这会创建一个无限的重定向循环。

我已经在网上搜寻了几个小时以寻求解决方案,但无济于事。提前致谢。

【问题讨论】:

  • 如果我错了,请纠正我,但是您正在捕获对/site/register 的所有请求,然后期望对/site/register 的请求不会被捕获?那是行不通的。相反,也许使用 PHP 或只是重定向到 /site/register_thanks_message?... 或其他东西

标签: .htaccess query-string infinite-loop


【解决方案1】:

如果register 是 PHP,使用类似:

<?php
  if(!array_key_exists('destination',$_GET))
    header('Location: '.http_build_query(
        array_merge($_GET,array('destination'=>'thankyou')));

【讨论】:

    猜你喜欢
    • 2011-08-13
    • 2018-10-10
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多