Take the 2-minute tour ×

I have a simple question, but I couldn't find the way to do it in my script.

Instead of this:


I need this:

share|improve this question
Search for short urls, its all over SO and the internet. –  Dainis Abols Jan 7 '13 at 14:22
And vanity urls, along with htaccess rewrites. If you are going to do this, make sure you are using absolute links in your documents, very important! –  Ben Carey Jan 7 '13 at 14:25
The maintainers of this site, jeff and joel ask that you don't respond to questions, no matter how poor they are, to advise them to "do a google search". The proper response is to down vote the question, the last thing the internet needs is to have someone land on a stackoverflow page, and read it, to find out that they should "do a google search". –  Eric Leschinski Jan 7 '13 at 14:25

1 Answer 1

up vote 1 down vote accepted

There are examples and tutorials all over the internet for this, you just need to search for the right keywords. Some examples:

  1. Vanity URL's
  2. Clean URL's
  3. .htaccess rewrites
  4. SEO friendly URL's

One site that I found helpful when learning about .htaccess rewrites was this one:


and a more friendly one:


It teaches you the basic stuff, but also goes into the deeper more complex stuff.

Useful Tip

One thing that is very important, otherwise you will run into issues with linked files, is to use absolute links in your HTML.

So instead of this:

<link rel="stylesheet" href="/css/stylsheet.css" />

You need to specify the whole address like so:

<link rel="stylesheet" href="//example.net/css/stylsheet.css" />

The reason why the above is necessary is because you are telling the server to interpret example.net/blah/blah/blah/ as example.net/blah.php?id=123, but the browser only sees it as example.net/blah/blah/blah and therefore the relative links get broken.


One additional thing to mention is that whilst this is handled server side, it is not PHP that handles the rewrite, it is Apache.

share|improve this answer

Your Answer


