redirecting urls while appending query string values

alan gerling asked on December 15, 2015 19:19

is there a way to redirect URLs based on the relative URL and append a query string to it?

for example:
relative url only
vanity-domain.com/eventA [redirect to] my-domain.com/events/A?track=1
vanity-domain.com/eventB [redirect to] my-domain.com/events/B?track=2

relative url + query string
vanity-domain.com/event?id=1 [redirect to] my-domain.com/events/A?track=1
vanity-domain.com/event?id=2 [redirect to] my-domain.com/events/B?track=2

note: this needs to be manageable by publishers

Recent Answers


Laura Frese answered on December 15, 2015 20:40

You could rig something up with javascript/jquery. There are a number of ways you might do it.

One way: Capture link clicks to change the path. Place this script (not tested) on the page you want to affect. If you want it to affect all links, place it globally. If you want to just grab links in a certain div, add the class before the "a".

$("a").click(function(){
    var url = $(this).attr("href");
    //fix the url if the links are absolute
    url = url.replace("http//:","");
    url = url.replace("www","");
    url = url.replace("vanity-domain.com","");
    window.location.href "http://www.my-domain.com" + url;

});
1 votesVote for this answer Mark as a Correct answer

alan gerling answered on December 15, 2015 20:45

Thanks Laura, the URLs i'm wanting to redirect are from links on other sites and promo materials. I need something manageable by publishers where they can just put in a URL and its redirect.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 15, 2015 22:00

1 votesVote for this answer Mark as a Correct answer

alan gerling answered on December 15, 2015 22:04

Thanks, i was just looking at this. it looks promising.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on December 15, 2015 22:05 (last edited on December 15, 2015 22:07)

Hi,

you could also have a look at the Kentico Marketplace. I've seen a few redirect modules recently:

https://devnet.kentico.com/marketplace/modules

Not sure if they will supports all your needs, but worth the to have a look since they are free to use.

// update: seems Brenden and yourself already suggested it before I could hit the post button :)

Greets,

David

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.