Apache 301 重定向和保留发布数据 [英] Apache 301 Redirect and preserving post data

查看:23
本文介绍了Apache 301 重定向和保留发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Apache 301 重定向到网站根目录中的redirect.cfm"实现了 SEO URL,该网站处理所有 URL 构建和内容交付.

I have implemented SEO URLs using Apache 301 redirects to a 'redirect.cfm' in the root of the website which handles all URL building and content delivering.

帖子数据在 301 重定向期间丢失.

Post data is lost during a 301 redirect.

目前无法找到解决方案,已尝试从重写中排除 post 方法 - 最坏的情况是我们可以将旧类型的 URL 用于 post 方法.

Unable to find a solution so far, have tried excluding post method from rewrites - worst case scenario we could use the old type URLs for post methods.

有什么可以做的吗?

谢谢

推荐答案

大约 2021 年更新此处的原始答案是在 307 状态代码重定向跨浏览器一致工作之前编写的.根据下面 Hashbrown 的回答,应该使用 307 状态代码.

Update circa 2021 The original answer here was written before 307 status code redirect worked consistently across browsers. As per Hashbrown's answer below, the 307 status code should be used.

旧答案POST 数据在重定向时被丢弃,因为客户端将对 301 指定的 URL 执行 GET 请求.

Old Answer POST data is discarded on redirect as a client will perform a GET request to the URL specified by the 301. Period.

唯一的选择是将 POST 参数转换为 GET 参数并将它们附加到您重定向到的 URL 的末尾.这不能在 .htaccess 文件重写中完成.

The only option is to convert the POST parameters to GET parameters and tack them onto the end of the URL you're redirecting to. This cannot be done in a .htaccess file rewrite.

一种选择是捕获对要重定向的 url 的 POST 请求,并将其传递到页面以处理重定向.您需要对代码中的参数进行转置,然后以这种方式发出带有附加新 url 参数的重定向标头.

One option is to catch POST requests to the url to be redirected and pass it off to a page to handle the redirect. You'd need to do the transposition of the parameters in code then issue the redirect header with the parameter appended new url that way.

更新:正如对此答案的评论所指出的,如果您确实重定向到另一个指定 POST 参数的 URL,并且该 URL 也可以在没有参数的情况下访问(或者参数是可变的),则您应该指定一个指向规范 URL 的链接页面.

Update: As pointed out in the comments to this answer, if you do redirect to another URL specifying POST parameters and that URL is also accessed without paramters (or the params are variable), you should specify a link to the canonical URL for the page.

假设 POST 表单重定向转置到以下 GET 资源:

Say the POST form redirects transposed to the following GET resource:

   http://www.example.com/finalpage.php?form_data_1=123&form_data_2=666

您可以将此链接记录添加到页面的头部:

You would add this link record to the head section of the page:

   <link rel="canonical" href="http://www.example.com/finalpage.php" />

这将确保将所有 SEO 价值赋予 http://www.example.com/finalpage.php 并避免重复内容可能出现的问题.

This would ensure all SEO value would be given to http://www.example.com/finalpage.php and avoid possible issues with duplicate content.

这篇关于Apache 301 重定向和保留发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆