URL 重写以删除参数但发送它

发布于 2024-09-07 20:40:20 字数 642 浏览 1 评论 0原文

我目前在我的网站上使用 register.php?referal=gamestand ,以便当用户通过推荐网站访问我的网站时,我可以跟踪有多少玩家从该地方注册。

referal=gamestand 将在注册过程中使用 echo $_GET['code'] 自动填写输入文本字段;

问题是...在 Google 上,我有大量来自这些推荐的链接,我想将它们 301 到我的 register.php 页面,以将 SEO 分数合并为一个,并最终删除这些愚蠢的 register.php?code=gamestand 风格来自谷歌的链接。

我有这个重写规则...它删除了 ?code=gamestand 位,但它实际上并没有传递参数,可能是因为它重定向并且不发送任何内容?

RewriteCond %{QUERY_STRING} ^(.*)code(.*)$
RewriteRule ^(.*)$ http://localhost/mywebsite/httpdocs/register.php? [R=301,L] 

它将把 register.php?code=gamestand 更改为 register.php 但正如我所说, $_GET['code'] 现在是空的,我回到了第一个!

如果有人知道任何事情,请提供任何帮助...谢谢!多姆

I currently use register.php?referal=gamestand on my website so that when the user visits my website through the referal website, I can track how many players have registered from that place.

referal=gamestand will automatically fill in an input textfield within the registration process using echo $_GET['code'];

The problem is... on Google I have loads of links from these referals and I'd like to 301 them to my register.php page to merge the SEO score into one and eventually remove these silly register.php?code=gamestand style links from google.

I've got this rewrite rule... which removes the ?code=gamestand bit, but it doesn't actually pass the parameter, probably because it's redirecting and sending nothing?

RewriteCond %{QUERY_STRING} ^(.*)code(.*)$
RewriteRule ^(.*)$ http://localhost/mywebsite/httpdocs/register.php? [R=301,L] 

it will change register.php?code=gamestand into register.php but as I said, $_GET['code'] is now empty and I'm back to square one!

Appreciate any help if anyone knows anything... Thanks! Dom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕梦 2024-09-14 20:40:20

您可以将引荐来源网址存储在会话变量中,然后重定向到没有代码的 register.php。您的 URL 将不再包含该代码,但可以通过会话访问它。

session_start();
if (isset($_GET['code'])) {
  $_SESSION['code'] = $_GET['code'];
  header('Location: register.php');
  exit;
}

...

echo $_SESSION['code'];

You could store the referrer in a session variable, then redirect to register.php without the code. Your URL won't contain the code any more, but it's available via the session.

session_start();
if (isset($_GET['code'])) {
  $_SESSION['code'] = $_GET['code'];
  header('Location: register.php');
  exit;
}

...

echo $_SESSION['code'];
私藏温柔 2024-09-14 20:40:20

将这些 URL 重定向到同一 URL 可能不会将您的 SEO 得分合并为一个。你现在的方法很好,不要乱用。

Redirecting these Urls to the same Url probably won't merge your SEO score into one. Your current method is fine, don't mess with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文