Mod re_write 机器人使用电子邮件活动中的外部链接

发布于 2024-10-25 01:57:25 字数 1015 浏览 1 评论 0原文

寻求一些帮助,让我的网站了解电子邮件中使用的链接,其中有一些 $_GET 变量可以整齐地显示在地址栏上。

该电子邮件是营销电子邮件活动的一部分,并发送到许多地址,电子邮件中的链接是动态的,并从电子邮件中获取嵌入信息来填充 $_GET 变量。

即 www.foobar.com?page=twenty2talk&name=Joe Bloggs&position=director&company=The Butchers&telephone=000&[电子邮件受保护]

因此,通过电子邮件中使用的上述链接示例,用户单击该链接并按照规范定向到我们的网站。

我遇到的问题是通过 mod re_write 转换该信息(其中 $_GET 变量内容始终会更改)。

在我的 .htaccess 文件中,我有以下 RewriteRule。

RewriteRule ^twenty2talk$       index.php?
                                  page=twenty-2-talk
                                  &name=$1
                                  &position=$2
                                  &company=$3
                                  &telephone=$4
                                  &email=$5 [L]

我希望我没有错过任何关键信息,但如果是这样,请给我一个责备。

预先感谢,

丹。

Looking for some help in regards to getting my site to understand a link used in an email which has a few $_GET vars to display neatly on the address bar.

The email is part of a marketing email campaign and sent out to a lot of addresses, the link in the email is dynamic and takes embedded information from the email to populate the $_GET vars.

I.e. www.foobar.com?page=twenty2talk&name=Joe Bloggs&position=director&company=The Butchers&telephone=000&[email protected]

So with the above link example used inside the emails the user clicks on that and is directed to our website as per the norm.

What I am having trouble with is then converting that information (where the $_GET vars content will always change) via mod re_write.

In my .htaccess file I have the following RewriteRule in place.

RewriteRule ^twenty2talk$       index.php?
                                  page=twenty-2-talk
                                  &name=$1
                                  &position=$2
                                  &company=$3
                                  &telephone=$4
                                  &email=$5 [L]

I'm hoping I have not missed out any key information, but if so please give me a telling off.

Thanks in advance,

Dan.

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

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

发布评论

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

评论(2

夏末染殇 2024-11-01 01:57:25

查询字符串附加

我假设您在电子邮件中的链接如下所示

www.foobar.com/twenty2talk?name=Joe Bloggs&position=director&
    company=The Butchers&telephone=000&[email protected]

,并且您想要访问此底层 URL

www.foobar.com/index.php?page=twenty2talk&name=Joe Bloggs&position=director&
    company=The Butchers&telephone=000&[email protected]

(插入换行符只是为了清楚起见。)

如果您确实需要匹配查询字符串中的内容(后面的内容?) ,你可以,但不能单独使用 RewriteRule。幸运的是你不需要。 mod_rewrite 中有一个名为“querystring追加”的东西,可以让你向现有的查询字符串添加一些内容。

RewriteRule ^twenty2talk/?$       index.php?page=twenty-2-talk [QSA,L]

该规则添加了 page=twenty-2-talk 但也保持名称等不变。 /? 部分允许编写带有或不带有尾部斜杠的起始 URL,这是一个很好的做法。问号字面意思是“匹配前一个字符 0 次或 1 次”。

如果您有多个此类活动,则可以编写更动态的规则:

RewriteRule ^(twenty2talk|winfreebeer|wowamazing)/?$ index.php?page=$1 [QSA,L]

在此特定示例中,twenty2talk 将被重写为不带连字符的 page=twenty2talk,而不是 page=twenty-2-talk。但这没关系——只需在 PHP 代码中检查两者即可。

面向未来——包罗万象的规则

将来,我建议对所有活动使用特殊的虚拟“文件夹”,这将允许包罗万象的规则。

RewriteRule ^campaigns/([^/]+)/?$ index.php?page=$1 [QSA,L]

该规则将捕获

www.foobar.com/campaigns/twenty2talk?name=...
www.foobar.com/campaigns/winfreebeer?name=...
www.foobar.com/campaigns/wowamazing?name=...

等,因此您无需为每个活动重写 .htaccess 文件。

Querystring append

I'm assuming your links in the e-mail look like this

www.foobar.com/twenty2talk?name=Joe Bloggs&position=director&
    company=The Butchers&telephone=000&[email protected]

and you want to get to this underlying URL

www.foobar.com/index.php?page=twenty2talk&name=Joe Bloggs&position=director&
    company=The Butchers&telephone=000&[email protected]

(Linebreaks inserted only for clarity.)

If you really needed to match stuff inside the query string (the stuff after ?), you could, but not using RewriteRule alone. Luckily you don't need to. There's something called querystring append in mod_rewrite that lets you just add something to the existing query string.

RewriteRule ^twenty2talk/?$       index.php?page=twenty-2-talk [QSA,L]

That rule adds page=twenty-2-talk but also keeps name etc untouched. The /? part allows for the start URL to be written with or without a trailing slash, which is good practice. The question mark literally means "match the previous character 0 or 1 time".

If you have several such campaigns, you could write a more dynamic rule:

RewriteRule ^(twenty2talk|winfreebeer|wowamazing)/?$ index.php?page=$1 [QSA,L]

In this particular example, twenty2talk wille be rewritten to page=twenty2talk without hyphens, rather than page=twenty-2-talk. But that's OK – just check for both in the PHP code.

For the future – a catch-all rule

In the future I'd recommend using a special virtual "folder" for all campaigns, which would allow for a catch-all rule.

RewriteRule ^campaigns/([^/]+)/?$ index.php?page=$1 [QSA,L]

That rule will catch

www.foobar.com/campaigns/twenty2talk?name=...
www.foobar.com/campaigns/winfreebeer?name=...
www.foobar.com/campaigns/wowamazing?name=...

etc. so you don't need to rewrite the .htaccess file for each campaign.

漫雪独思 2024-11-01 01:57:25

您的重写规则不正确,您使用占位符($X)但您没有捕获任何内容。

此外,如果我读它,它会告诉“www.foobar.com/twenty2talk”到www.foobar.com/index.php?page=twenty-2-talk&name=$1&position=$2&company=$3&电话=$4&电子邮件=$5 [L]

我不确定这就是你想要实现的......

你能写下一个可以用来重写模块的例子(很好的一个)以及它必须导致的一个例子( php 获取一个)

Your rewrite rule is incorrect, you use placeholders ($X) but you dont catch anything.

Moreover if I read it it tells "www.foobar.com/twenty2talk" to www.foobar.com/index.php?page=twenty-2-talk&name=$1&position=$2&company=$3&telephone=$4&email=$5 [L]

I am not sure thats what you want to acheive ...

Can you write down an example that may be given to rewrite module (nice one) and the one it must lead to (the php get one)

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