Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to shorten some links, by re-directing. I'm wondering what the best way to do this is: I have files at www.mysite.com/qr/quicklinks/User/ but I'm wondering if it's possible to somehow make it so it's just www.mysite.com/user? This would be brilliant if it can be done and possibly in PHP too? I've tried a few things but nothing seems to be working.

share|improve this question
up vote 0 down vote accepted

Use a .htaccess file and mod_rewrite:

RewriteEngine on
RewriteBase /
RewriteRule ^qr/quicklinks/(.*)$ http://www.example.com/$1 [R=301,L]

Depending on the server, that's case-sensitive. Adjust the URL if necessary.

If that fails, try this PHP code:

Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://www.site.com/Users/" ); 

It won't support wildcard files though.

share|improve this answer
That doesn't seem to be working. I've created a .htaccess file and places it on the server, then put your code into it. Does anything else have to be in the .htaccess file? – Joe Turner Jun 25 '12 at 13:56
It requires that mod_rewrite is enabled, I updated my answer with some PHP code. – ionFish Jun 25 '12 at 13:58
Struggling with this, I've never really set up a .htaccess file before. It's not really doing anything, just not letting me access anything on my server now. I delete the .htaccess file and it's back to normal... Is there anything that a .htaccess file MUST have in order to run? – Joe Turner Jun 25 '12 at 14:07
Hold on, which directory did you put the .htaccess? It could also be my syntax, that was done from memory. I'll verify it on my server quickly. – ionFish Jun 25 '12 at 14:11
I put it in the root. I'm looking for it to do the following if possible dude: www.mysite.com/QR/QuickLinks/'XXXXXX' - So, whatever is 'XXXXX' can be found by going to www.mysite.com/'XXXXXX' – Joe Turner Jun 25 '12 at 14:16

You know you can just use Bit.ly for free and they have an api where your site can generate URLs.

share|improve this answer
I'll have a look at setting this up. Thanks. – Joe Turner Jun 26 '12 at 10:03
Bitly is cool because they handle everything for you. If you want something that you can host yourself, then yourls.org is a nice free start. – Frank Jun 26 '12 at 10:56
I'm having a bit of trouble actually implementing the Bit.Ly at the moment. The way my site works is, the user inputs a contract number and then that creates a directory, calls for a QR Code (Via Google) using the link.. How would I get that Bit.Ly into the Google script at the same time? – Joe Turner Jun 26 '12 at 11:27
Where is the google script you are using? Ill take a look – Frank Jul 11 '12 at 17:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.