我如何使用您的用户名创建动态网址?(How can I create a dynamic url with your username?)

编程入门 行业动态 更新时间:2024-10-28 07:21:27
我如何使用您的用户名创建动态网址?(How can I create a dynamic url with your username?)

我想创建一个动态网址,以便当我从我的网站登录时,我的用户名将显示在网址上。 例如,说我登录:

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.html

Result: 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.html

Result: 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.html

Result: http://www.example-website.com/john-smith/auth

更多推荐

本文发布于:2023-08-02 09:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:您的   如何使用   用户名   网址   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!