Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts

    .htaccess rewrite question

    PHP forum may not be the best place for this question, but I am writing everything in PHP on a Linux box, so it will use the .htaccess for its information.

    I have designed a community site and currently I have the user info detail pages at

    http://mydomain.com/detail.php?userid=123

    and my users are asking if I can make their userpages look in the URL like this --

    http://mydomain.com/username

    I know this will have to do with .htaccess rewrites, but how will I be able to port my current VERY complicated pages over to this system of rewrites and make it all work?

    Currently here are my isssues I have spotted.

    1. We don't check for unique usernames because they are actually studio names registering in the studio finder space of the site, so their could be the same name studio in teh database, which wasn't a problem becuase the ID was the way we were differentiating before, so I will need to add some form of not allowing duplicate studio/usernames.

    2. All the php in the page looks only for the _GET['studio_id'] variable now --- I assume I will have to add php code to look for the /username now, and then match that somehow to the mysql query I am running currently which uses the studio_id ---

    Can someone walk me through the necessary steps I am going to have to take to make this all work?

    Will I need to manually add a studio name to the rewrite rules each time one is added ? If this is the case, then it's a deal-breaker, as we have 40 studios a day registering....

    I was assuming I could somehow get the .htaccess file to make the
    url http://mydomain.com/username

    actually load the page --

    http://mydomain.com/detail.php?studio_id=123 and the /username would help determine what the studio_id variable number would actually be?

    I know this somehow possible, as facebook and myspace do it this way....but what I don't know is if it will require a full-re writing of my current code --

    Any help would be greatly appreciated.

    Thanks.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by JimNayzium View Post
    I know this will have to do with .htaccess rewrites, but how will I be able to port my current VERY complicated pages over to this system of rewrites and make it all work?
    You don't. You have the rewrite check to see if the file/folder requested exists, and if it doesn't you pass everything else to a single page for PHP to process.
    Quote Originally Posted by JimNayzium View Post
    Currently here are my isssues I have spotted.

    1. We don't check for unique usernames because they are actually studio names registering in the studio finder space of the site, so their could be the same name studio in teh database, which wasn't a problem becuase the ID was the way we were differentiating before, so I will need to add some form of not allowing duplicate studio/usernames.
    Yes, you need some sort of unique field. You might consider adding another field to the user table called "urlname" or similar that will initially be their username unless it's taken.
    Quote Originally Posted by JimNayzium View Post
    2. All the php in the page looks only for the _GET['studio_id'] variable now --- I assume I will have to add php code to look for the /username now, and then match that somehow to the mysql query I am running currently which uses the studio_id ---
    Yes, you will have to search for their username based on the value given in the url. Or, what you might use is url.com/username/123 (or url.com/123/username) and ignore the username; just use the id to lookup their user info.
    Quote Originally Posted by JimNayzium View Post
    Will I need to manually add a studio name to the rewrite rules each time one is added ?
    No, see above.
    Quote Originally Posted by JimNayzium View Post
    what I don't know is if it will require a full-re writing of my current code
    Nope, just a little work.

    If you don't want to attempt it yourself there's a forum at the bottom for paid projects.

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts
    You don't. You have the rewrite check to see if the file/folder requested exists, and if it doesn't you pass everything else to a single page for PHP to process.
    Could you elaborate on this a little. Are you saying that by default a url like

    mydomain.com/username will be looking for the index.html file in teh username folder - and since it doesn't exist...the .htaccess file will have code in it that will say something like,

    "when you find a bad url like above then load this .php to execute before giving a 404 error"

    then it will load this .php where code will then look in the database based on teh url.com/username - username value --- (which is why the username will then have to be unique...and be another field in the table to then tie-into the already present user-id code...)

    So the other .php page will say basically...match up the /username with the userid in the table ... and load that detail.php?studio_id=123 page now that it knows which page to load....

    all the while, keeping the url pretty....

    Is this basically what you are saying will happen when it all works properly?

    Thanks.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Yes.

  • #5
    New Coder
    Join Date
    Nov 2007
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Can you point me to an .htaccess tutorial that will load the external php file upon the error?

    I have a small grasph of htaccess and given a good tutorial I could probably get all the way home....

    thanks.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    No, I don't. But you can find all the information you need by searching Google or the Apache manual.

  • #7
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    In case of real laziness, this forum usually has some good articles/information:

    http://forum.modrewrite.com/


  •  

    Posting Permissions

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