Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

URL redirection dilema

Options
  • 03-10-2005 4:55pm
    #1
    Registered Users Posts: 538 ✭✭✭


    Hi guys,

    I am developing a site and its php mysql. Anyways they have a list of users that can be displayed on the site. so for a user (eg john smith) the url is

    http://www.mysite.com/user.php?id=143

    Now the client said would it be possible to have john smith in the url like so

    http://www.mysite.com/johnsmith

    i know that this normally means that a folder johnsmith will need to be there. is there a script or a way that will catch johnsmith and query the database and give it the original url.(of course the name johnsmith as the reference will be stored in the database)

    If you have any question or I havent been clear about anything just ask.

    Thanks for looking.
    M


Comments

  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    well,you could have Error 404 redirect...
    otherwise, a better solution is subdomains if their provided= http://johnsmith.mysite.com

    edit:
    actually, do you have server-side scripting on the hosting (PHP,JSP,ASP,etc.)
    Possibly script to check HTTP headers?
    really not good ideas. subdomain remains my fav.


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    There's nothing out of the box to do it, but if the webserver is Apache all you have to do is use mod_rewrite or ErrorDocument to map these requests to a script that will query MySQL for the id of the relevant name, and then use user.php to deliver the right details.

    I'd recommend using mod_rewrite, because otherwise genuine 404 errors will be trapped by the script. However in that case it would be a good idea to move user queries to a separate namespace (like site.com/users/username) to prevent conflicts.

    adam


  • Registered Users Posts: 538 ✭✭✭mjquinno


    thanks to both of you guys,

    Adam but if the user was not in the database woudnt that not mean that it was a genuine 404 error and therefore show the 404 error page nad not redirect?

    Sorry if this i gone over my head monday :mad:


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    mjquinno wrote:
    Adam but if the user was not in the database woudnt that not mean that it was a genuine 404 error and therefore show the 404 error page nad not redirect?
    Both would be genuine 404 errors, you'd be using this script to handle ALL 404 errors. You could have the script output a 404 message if nothing was found in the database, but that's a hack. (The entire solution is a hack, but a common one.)

    Using RewriteRules is the better approach, this is the kind of thing mod_rewrite was designed for.

    adam


  • Registered Users Posts: 538 ✭✭✭mjquinno


    O right,

    Thats great thanks for the info. Ill get up to speed on mod_rewrite

    Thanks again,

    M


  • Advertisement
Advertisement