views:

57

answers:

1

Hi all,

I wanted to have users within my website to have their own URL like http://mysite.com/username (similar to GitHub, e.g. my account is http:// github. com/sr3d). This would help with SEO since every profile is under the same domain, as apposed to the sub-domain approach.

My site is running on Rails and Nginx/Passenger. Currently I have a solution using a bunch of rewrite in the nginx.conf file, and hard-coded controller names (with namespace support as well). I can share include the nginx.conf here if you guys want to take a look.

I wanted to know if there's a better way of making the URL pretty like that.

(If you suggest a better place to post this question then please let me know)

Cheers,

Alex

+1  A: 

Place this line right at the end of the routes.rb file, ( So that this doesn't interfere with other controller routes )

map.connect "/:username", :controller=> "users", :action => "show"

in users_controller, use the following line to fetch the user

  @user = User.find_by_username(params[:username]) 

I don't think this would require any nginx magic or url rewrites.

HTH

Rishav Rastogi
It would involve to blacklist certain usernames to avoid ambiguity with routes defined earlier.
hurikhan77
thanks for pointing that out, blacklisting certain usernames would be required.
Rishav Rastogi