开发者

Mod re_write bot working with external links from an email campaign

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=joe.bloggs@thebutchers.co.uk

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 c开发者_运维技巧onverting 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.


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=joe.bloggs@thebutchers.co.uk

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=joe.bloggs@thebutchers.co.uk

(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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜