SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do url shorteners work

    Hello

    I am new to this site and fairly new to PHP.

    How do url shorteners work

    When you go on a URL shortener site and type in a url you get a link like this:

    domain/1234

    How is the data after the forward slash accessed because it's not a query string.

    I don't want to make such as service but I was just wondering
    whether using the query string would be just as good a method to use eg:

    domain?a=1234

    Like I say I am fairly new to PHP. I know the basics although I know nothing about OO programming.

    Thanks for your help

    Lewis

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are new to this site, why don't you take a look to the posts here?
    May be some of them on the same problem?

    Just a few lines below:
    http://www.sitepoint.com/forums/showthread.php?t=647280

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for the reply

    What I want to do is have

    domain/12345

    and use the data to query a database.

    I saw a parse_url function that would get that part of the url and I could use the request function to access the url

    Would this work or does it have to be done via php configuration.

    Thanks

    Lewis

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope

  5. #5
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why?

  6. #6
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there are no file named 12345 on your server

  7. #7
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The benefits of clean URL's are:
    - Better for marketing purposes
    - Better for SEO
    - Good to know because a lot of clients will ask for them

    There's a few different methods of creating clean url's. The method I use is to insert this in to the htacces file:

    Code:
    # this is the initialization
    Options         +FollowSymLinks
    RewriteEngine   On
    RewriteBase     /
    # these are the rewrite conditions
    RewriteCond     %{REQUEST_FILENAME}     !-f
    RewriteCond     %{REQUEST_FILENAME}     !-d
    # and finally, the rewrite rules
    RewriteRule     ^([a-zA-Z0-9\-_]+)/?$    /index.php?go=$1 [L,QSA]
    This will convert "index.php/page" or "/page" into "index.php?go=page" which you can parse normally.

  8. #8
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lewisb87 View Post
    Hi

    Thanks for the reply

    What I want to do is have

    domain/12345

    and use the data to query a database.

    I saw a parse_url function that would get that part of the url and I could use the request function to access the url

    Would this work or does it have to be done via php configuration.

    Thanks

    Lewis
    If you want to use clean urls, It's better to start with apache's mod_rewrite & PHP's $_SERVER['PATH_INFO'] together.

  9. #9
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    590
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey I didn't know there is such thing as url shorteners. I think this is for people who don't want to trouble themselves with htaccess mod re-writing and regex.
    Don't Panic


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •