0

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.

2 Answers 2

0

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:

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

It won't support wildcard files though.

11
  • 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
    Commented Jun 25, 2012 at 13:56
  • It requires that mod_rewrite is enabled, I updated my answer with some PHP code.
    – ionFish
    Commented Jun 25, 2012 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
    Commented Jun 25, 2012 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
    Commented Jun 25, 2012 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
    Commented Jun 25, 2012 at 14:16
0

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

3
  • 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
    Commented Jun 26, 2012 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
    Commented Jun 26, 2012 at 11:27
  • Where is the google script you are using? Ill take a look
    – Frank
    Commented Jul 11, 2012 at 17:16

Your Answer

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

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