开发者

How get a like twitter url

i would like a simple help... i have a url like this: examp开发者_开发百科le.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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜