...

View Full Version : .htaccess rewrite question



JimNayzium
11-25-2007, 07:03 PM
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.

Inigoesdr
11-25-2007, 08:25 PM
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.

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.

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.

Will I need to manually add a studio name to the rewrite rules each time one is added ?
No, see above.

what I don't know is if it will require a full-re writing of my current code
Nope, just a little work. :thumbsup:

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

JimNayzium
11-26-2007, 04:22 PM
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.

Inigoesdr
11-26-2007, 08:39 PM
Yes. :)

JimNayzium
11-26-2007, 08:53 PM
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.

Inigoesdr
11-26-2007, 11:01 PM
No, I don't. But you can find all the information you need by searching Google or the Apache manual.

aedrin
11-27-2007, 04:25 PM
In case of real laziness, this forum usually has some good articles/information:

http://forum.modrewrite.com/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum