我正试图实现一个"post request get"模式的SEO原因,就像在这个例子中解释的那样:https://www.advertising.de/seo/wiki/prg-pattern.html
我的实现包含一个伪链接元素,通过CSS样式像一个链接:
<span data-prg="redirect_url.html" class="btn redir-link" title="test">PRG Link test</span>
jquery AJAX POST调用
<script type="text/javascript">
var request;
$(function() {
$('.redir-link[data-prg]').click(function (e) {
var $self = $(this);
request = $.ajax({
url: "/prg.php",
type: "post",
data: {
url: $self.data("prg")
}
});
});
});
</script>
创建重定向URL的PHP文件,它应该通过GET进行302重定向
header("Location:".$_POST['url'], true, 302);
exit;
apache日志说明实现工作:
"POST/pg .php HTTP/1.1"GET/redirect_url.html HTTP/1.1" 200
但是浏览器内的页面不会改变。我怀疑通过ajax调用的php文件会改变,但这不是我想要的。原页面应重定向。
我怎样才能获得原始页面的302重定向?
您不能在ajax页面中重定向,该页面对用户不可用,做一个简单的表单,将触发post请求到prg中的/prg.php
,然后重定向回