tags:

views:

107

answers:

4

hi ... i would like a simple help... i have a url like this: example.com/profile.php?id= & name=

my .htaccess file like this.

RewriteRule ^profile/(.)/(.) profile.php?id=$1&name=$2

so i have a end url like this: example.com/profile/id/name

i can make example.com/id

but how can i get a url like this:

example.com/name

??

thax

A: 

Obviously, your profile.php script is expecting two GET variables, and your desired URL only has one. So you will probably have to change both the script and your database schema.

Matthew Flaschen
A: 

Your rewrite rule is subtly wrong. Yours will only select a single character in each of the bracketed parts. If you put a * after each dot, it will instead select one or more characters which I think is what you need.

RewriteRule ^profile/(.*)/(.*) profile.php?id=$1&name=$2
slightlymore
This is true, but does not quite answer the question. He is looking for a path with only 1 forward-slash.
Matthew Flaschen
oops - my mistake - mis-read the question :(
slightlymore
A: 

If what you're looking for is exactly this:

example.com/name

You will need to change your profile.php to only expect the name variable, and use it to query the database.

I believe previously you had something like:

mysql_query("SELECT * from table where id=$id");

You will need to change it to be

mysql_query("SELECT * from table where name$name");

So you are telling your page to query the user by the name, instead of by the ID.

There's a few drawbacks related to this, as your query won't be as fast as it used to be, as I believe your name column is not the primary key, therefore no indexing.

Twitter uses Rails, so they will be calling it in a slightly different way using something like (onMissingMethod):

get_user_by_username()

Which isn't great either, as it's still querying the database by a string, but has some performance improvements to enable rails to do that.

Your htaccess will then looki like:

RewriteRule ^(.*) profile.php?name=$1

Hope that answers your question

Marcos Placona
really good...thx for all...really really...
fabio
fabio
A: 

I have the exact same problem but, I'm not using PHP my applications runs on java struts. Since I'm new to struts I don´t know if I could apply this same solution or maybe there is a simpler way. Could you guys give some pointers?

Thanks!!

Dreyser Eguia