Monday, June 6, 2011

Profile link system site.com/username Apache

This one is fairly simple but took me a while to figure out due to lack of examples/how to on the web for this thing:

  1. Make sure your server has mod_rewrite on! That one is easy to figure find a how to online if you are not sure.
  2. Then, make sure you have a .htaccess file you can modify or create
  3. Link a unique field to a user id in the Database so he can chose his site: EG: On google for example, it would look like www.google.com/neobahamut20
  4. In your .htaccess file, add the following:
    # PROFILER
    RewriteEngine On

    RewriteRule ^([\w_-]+)$ profile.php?u=$1
    # END PROFILER


  5.  And it should work. Make sure however that you do not allow dots when the user chooses his name with this one as it will not be found instead of redirecting to a profile page.
  6. Don't ask why this need a  ^ at the beginning when normally the regex wouldn't require one. (if you know, please comment!)

No comments:

Post a Comment