Ashwin
Ashwin

Reputation: 607

Multiple links to the same webpage

I want to make a script which will have generate random links to the same page. I know I can use a random generator for random alphanumeric string but how can I implement that and redirect it to the same page.

For example:

All these links should be redirected when clicked to the same page, www.domain.com. How can I do that?

Upvotes: 0

Views: 251

Answers (3)

Martyn
Martyn

Reputation: 384

If you want to redirect ALL random number pages to the same page you can simply use .htaccess to track the URL with some pattern (using regular expressions) and redirect them straight to some page.

If you want to track the number you can use .htaccess to rewrite the URL to

http://www.domain.com/page.php?id=23412
http://www.domain.com/page.php?id=86756

Then you can use $_GET['id'] to get the numbers and do something with them. When the processing is done the following function can be used to redirect the user to a URL of your preference:

header('Location:http://www.domain.com');

Apache Guide to URL rewriting: URL Rewriting Guide

Upvotes: 0

Sabeen Malik
Sabeen Malik

Reputation: 10880

Really depends on how you envision your urls. One simple way could be

http://www.domain.com/page/1234
http://www.domain.com/page/5432

If you are ok with that url structure, then you can do a htaccess rewrite to point all requests containing /page/ to the same place.

It would be something on these lines

RewriteRule ^/page/(.*)$ common.php

The idea is to have something in the url that is common across all the urls, in this case its 'page'

Upvotes: 1

Godzilla
Godzilla

Reputation: 318

You can always use rand() or mt_rand() to generate a random integer and append it to your url.

Upvotes: 0

Related Questions