我想创建一个动态网址,以便当我从我的网站登录时,我的用户名将显示在网址上。 例如,说我登录:
http://example-website.com
用我的用户名myname。 该网址应该成为
http://example-website.com/myname
但实际上该网页是loginsuccess.php,并带有myname的别名,这是我的用户名
我怎样才能做到这一点?
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:
http://example-website.com
with my username myname. The url should become
http://example-website.com/myname
but actually the web page is loginsuccess.php with an alias of myname which is my username
How can I do this?
最满意答案
使用.htaccess和RewriteEngine这其实很简单。 在下面的例子中,我将使用一些非常简单的(.*)正则表达式,它只是一个通配符,因此一切都会被接受( a-zA-z0-9 )。
/username 前缀 profile
RewriteEngine on RewriteRule ^profile/(.*) user_profile.php?username=$1 ErrorDocument 404 /pathtofile/404.html结果: http : //www.example-website.com/profile/john-smith
只使用username ,这个选项将需要某种Routing类。
RewriteEngine on RewriteRule ^(.*) user_profile.php?username=$1 ErrorDocument 404 /pathtofile/404.html结果: http : //www.example-website.com/john-smith
使用带后缀 auth RewriteEngine
RewriteEngine on RewriteRule ^(.*)/auth auth_user.php?username=$1&q=auth ErrorDocument 404 /pathtofile/404.html结果: http : //www.example-website.com/john-smith/auth
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).
/username prefixed with profile
RewriteEngine on RewriteRule ^profile/(.*) user_profile.php?username=$1 ErrorDocument 404 /pathtofile/404.htmlResult: http://www.example-website.com/profile/john-smith
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.htmlResult: http://www.example-website.com/john-smith
Using RewriteEngine with Suffix auth
RewriteEngine on RewriteRule ^(.*)/auth auth_user.php?username=$1&q=auth ErrorDocument 404 /pathtofile/404.htmlResult: http://www.example-website.com/john-smith/auth
更多推荐
发布评论