开发者

Need to have either example.com/username or username.example.com, but how?

I'm almost finished developing my large project, however I would love it if I could make it so instead of having the users profil开发者_如何学JAVAe pages at: http://example.com/profile/username/USERNAME

(i'm currently using .htaccess to rewrite the GET data into forward slashes and profile(.php) being read as just 'profile' profile.php also parses the url correctly to retrieve the GET data)

But it would be some much better if I could do it so that it's like http://www.example.com/USERNAME (preferred) or http://www.USERNAME.example.com

Any ideas or resources?

Thanks, Stefan


In your .htaccess in the root, add

RewriteRule ^/([^/]+)/?    /profile/username/$1

This matches paths that don't include a slash (so no directories in the path) and suffixes the path to /profile/username/. The path can include an optional final slash.

(+1 for the comment about namespaces - it's a little dangrous having usernames in the root of your site. I've tried to limit the impact of this by only giving out the namespace comprising a single directory. Paths with multiple directories will be handled as normal.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜