我想創建一個動態url,這樣當我從我的網站登錄時,我的用戶名將顯示在url上。例如,假設我登錄有:如何使用您的用戶名創建動態網址?
與我的用戶名MYNAME。 URL應該成爲
http://example-website.com/myname
但實際上網頁是loginsuccess.php與MYNAME的別名,這是我的用戶名
我怎樣才能做到這一點?
我想創建一個動態url,這樣當我從我的網站登錄時,我的用戶名將顯示在url上。例如,假設我登錄有:如何使用您的用戶名創建動態網址?
與我的用戶名MYNAME。 URL應該成爲
http://example-website.com/myname
但實際上網頁是loginsuccess.php與MYNAME的別名,這是我的用戶名
我怎樣才能做到這一點?
這實際上很容易與.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
使用RewriteEngine敘述與後綴auth
RewriteEngine on
RewriteRule ^(.*)/auth auth_user.php?username=$1&q=auth
ErrorDocument 404 /pathtofile/404.html
快速提示:在一個表中
有關詳細說明,請參閱Facebook Like Custom Profile URL PHP。
[Facebook的,如自定義配置文件的URL PHP(可能的重複HTTP ://堆棧overflow.com/q/10595556/254830)作爲RakeshS提到。 – doppelgreener 2013-04-30 04:41:58