Gitub url style

I wanted the users on my website to have their own URL, for example http://mysite.com/username (similar to GitHub, for example, my account is http: // github.com/sr3d). This will help in SEO, since each profile is in the same domain as in the subdomain approach.

My site runs on Rails and Nginx / Passenger. I currently have a solution using a bunch of rewrites in the nginx.conf file and hard-coded controller names (with namespace support). I can share nginx.conf with it if you want to look.

I wanted to know if there is a better way to make the URL this way.

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

Greetings

Alex

0
source share
1 answer

Place this line directly at the end of the route.rb file (so that it does not interfere with other controller routes)

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

in users_controller, use the following line to retrieve the user

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

I don’t think that this would require any nginx magic or rewriting of URLs.

NTN

+5
source

All Articles