Users on my site are given unique URL's for me to then track how many people they have referred to my site.

IE: http://www.example.com/FQ3DL (FQ3DL being the unique code/url)

The first thing I'd like to do is when a user goes to that link, it displays the homepage http://www.example.com/ rather than a 404 error

The second thing is, how would I track how many people have visited that URL? Only through Google Analytics or is there another way to manage it?


  • For this you should have to create a coding mechanism, which will count the link open, location and date from that URL. You need to discuss this with some developer. Commented Dec 25, 2020 at 21:30

1 Answer 1


I would probably write the code myself to track them. Although perhaps it would be easier trying to hook it into analytics. I'm not sure how to do that.

To do the re-direct you would want to use .htaccess (providing you're using Apache server) The .htacess file might look something like this:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([A-Z0-9]{5})$ track.php?id=$1 [L]

The RewriteRule there will match someone going to example.com/HJK7D Basically example.com/ and any combination of 5 capital letters and or numbers. This will get re-written and the server will actually pull up track.php?id=HJK7D (in this case)

So drop that .htaccess into the main root directory of your website. Then create a file called track.php which might look something like this:

    if(isset($_GET['id'] && strlen($_GET['id'])==5){
        setcookie("id", $_GET['id'], time()+1209600); // expires in 2 weeks

    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.example.com/");

Then use the cookie $_COOKIE['id'] to track your visitor through your site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.