如何创建一个动态的URL与您的用户名? [英] How can I create a dynamic url with your username?

查看:176
本文介绍了如何创建一个动态的URL与您的用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个动态的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:

http://example-website.com

我的用户名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 RewriteEngine叙述。在下面的例子中我将使用一些非常简单的(。*)正则表达式,这仅仅是一个通配符让一切都将被接受( 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-史密斯

只有用户名工作,此选项将需要某种形式的<一个href="http://stackoverflow.com/questions/115629/simplest-php-routing-framework"><$c$c>Routing类。

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与您的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆