问题描述
我想创建一个动态的URL,这样当我从我的网站上登录自己的用户名将会在URL上显示。例如,假设我有登录:
I want to create a dynamic url such that when I log in from my website my username will be shown on the url. For example, say I log in with:
我的用户名MYNAME。网址应成为
with my username myname. The url should become
http://example-website.com/myname
但实际上网页是loginsuccess.php与MYNAME的别名,这是我的用户名
but actually the web page is loginsuccess.php with an alias of myname which is my username
我怎样才能做到这一点?
How can I do this?
推荐答案
这实际上是pretty的易于使用的.htaccess
和。在下面的例子中我将使用一些非常简单的(。*)
正则表达式,这仅仅是一个通配符让一切都将被接受( A -za-Z0-9
)。
This is actually pretty easy with .htaccess
and RewriteEngine. In the example below I'll be using some really simple (.*)
regex, which is just a wildcard so that everything will be accepted (a-zA-z0-9
).
/用户名
的 prefixed 的与简介
/username
prefixed with profile
RewriteEngine on
RewriteRule ^profile/(.*) user_profile.php?username=$1
ErrorDocument 404 /pathtofile/404.html
结果: http://www.example-website.com/profile/john-史密斯
只有用户名
工作,此选项将需要某种形式的<$c$c>Routing$c$c>类。
Working with just username
, this option will require some sort of Routing
class.
RewriteEngine on
RewriteRule ^(.*) user_profile.php?username=$1
ErrorDocument 404 /pathtofile/404.html
结果: http://www.example-website.com/john-smith
使用RewriteEngine叙述与说明的 AUTH
Using RewriteEngine with Suffix auth
RewriteEngine on
RewriteRule ^(.*)/auth auth_user.php?username=$1&q=auth
ErrorDocument 404 /pathtofile/404.html
结果: http://www.example-website.com/john-smith/ AUTH
这篇关于如何创建一个动态的URL与您的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!