1

i am trying to implement a shortURL feature to my website. Calling the URL http://example.com/T35T should redirect the user to a specific website. My problem is getting the keyword behind the top level domain. By calling the URL, the webserver tries to locate the folder T35T and throws an error.

How can i stop the server (apache) from searching for the folder, so i can read the URL via PHP and redirect the user correctly.

Thanks you for your answers!

Greetings

2 Answers2

0

You would Save your Url in a Database and create a Id for it.

Then you would encode the id which should ne int to a base of a-zA-Z0-9-.,+=

So 1 would be a, 27 would be A, 55 => 0, 65 => -, 69 => =, 70 => aa, 71 => ab and so on.

This is what you are sending your Visitor.

If your Visitor call the Url (Use Url Rewrite for this) you can Decode your Id, read in the Database for the Url for this Id, and redirect.

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
0

The question URL rewriting with PHP is more or less what you need (or this one How can I display SEO friendly URLs using mod_rewrite?).

What you need is to tell apache to convert this URL to a page that you can manage.

From the accepted answer by Niels Keurentjes (modified to your needs):

Add a file called .htaccess in your root folder, and add something like this:

RewriteEngine on
RewriteRule ^/([a-zA-Z0-9]+)$ /redirect.php?id=$1

This will tell Apache to enable mod_rewrite for this folder, and if it gets asked a URL matching the regular expression it rewrites it internally to what you want, without the end user seeing it.

Then in the page redirect.php you can do a HTTP redirect based on the id.

You can also see the official guide.

Community
  • 1
  • 1
PhoneixS
  • 10,574
  • 6
  • 57
  • 73