开发者

github url style

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 he开发者_JAVA百科lp 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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜