[英]Any easy, noncluttering way to set up “mydomain.com/username” using PHP?
Simply put, when a user wants people to be able to go to their profile, we want them to be able to just say go to mydomain.com/username
. 简而言之,当用户希望人们能够访问他们的个人资料时,我们希望他们能够说“转到
mydomain.com/username
。 The real user page would be at something like mydomain.com/users/page.php?id=1325
which doesn't really help users. 真正的用户页面将位于
mydomain.com/users/page.php?id=1325
,这实际上并不能帮助用户。
The problem: I've been doing PHP for some time, and have never had the need to do this. 问题:我从事PHP已有一段时间了,从来没有必要这样做。 I don't have a clue where to even start?
我不知道从哪里开始? I wouldn't want to do something as naive as just creating actual folders with redirects in them or something....
我不想做一些天真的事情,就像创建带有重定向或其他内容的实际文件夹一样。
Can anybody tell me how to go about this in php? 谁能告诉我如何在php中进行此操作?
Y'all are the greatest! 你们都是最伟大的!
Provided you are on an apache server look up .htaccess
and mod_rewrite
, it all happens outside of PHP. 假设您在apache服务器上查找
.htaccess
和mod_rewrite
,则所有这些操作均在PHP外部进行。
Example for your .htaccess
: .htaccess
示例:
RewriteEngine on
RewriteRule ^([0-9a-zA-Z]+)([\/]?)$ /user/profile.php?name=$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.