URL与MySQL数据库重写重写、数据库、URL、MySQL

2023-09-02 01:08:41 作者:糊里糊涂

可能重复:   的.htaccess的URL与PHP 重写

Possible Duplicate: .htaccess url rewriting with php

在我的网站主页有多个用户,上市。每个用户都有查看资料链接,您可以到 www.mysite.com/user-profiles/profile.php?id=32 ID 是与用户相关。

The homepage on my website has a number of users, listed. Each user has 'view profile' link that takes you to www.mysite.com/user-profiles/profile.php?id=32, the id being relevant to the user.

是否有可能使用URL重写,找到在数据库中ID的用户名和surnamce并重写它太像?

Is it possible to use URL Rewriting to find the name and surnamce of the user for that ID in the database and rewrite it too something like?

www.mysite.com/user-profiles/john-a-doe

任何帮助将是很大的AP preciated ...

Any help would be greatly appreciated...

推荐答案

我建议做这种方式

在下面的格式打印网址 mysite.com/user-profiles/(ID)/(姓名)然后用它来重写:

Print URLs in the following format mysite.com/user-profiles/(ID)/(NAME) then use this to rewrite:

RewriteRule ^user-profiles/([^/]*)/([^/]*)$ /user-profiles/profile.php?id=$1&name=$2 [L]

然后在 profile.php SELECT ID 名称

注:有几种方法可以实现你想要的,但因为你使用的是全名为(名称)这是会导致(由Ronn0注)的一个问题当两个用户(或更多)具有相同的名称,用我所建议你能消除这个问题。

Note: There are several ways to achieve what you want, but since you're using Full Name for (NAME) that's gonna cause a problem (noted by Ronn0) when two users (or more) have the same name, with what I've suggested you're able to eliminate that problem.