How To Create A Profile In Facebook?

How can I create Facebook- and Twitter-like profile URLs with mod_rewrite?

  • I want to create a profile page on my web app, something that would rewrite http://example.com/UserName to http://example.com/profile.php? id=username&goto=friends. I have tried using this : RewriteRule (.*)/(.*) profile.php?id=$1&goto=$2 RewriteRule (.*)/(.*)/ profile.php?id=$1&goto=$2 Whenever I apply this to the .htaccess file, all pages gets an "Internal Error".

  • Answer:

    Syntactically your rules are fine, so I'm guessing you have a typo somewhere else in your file. Make sure you're not using directives that aren't allowed in .htaccess. Apache's error log might have some details if you have that enabled. In terms of correctness, there are some cases those rules won't handle the way you want. If someone enters example.com/bulat/friends/junk, $1 will be "bulat/friends" and $2 will be "junk" because (.*) matches any number of slashes. If a browser appends an extra slash, like example.com/bulat/, the first rule will match and $2 will be set but empty. I've set up a demo at an extra domain I have and made some changes to fix those problems. The modified rules are live and visible at http://laserbeans.org. The originals are at http://laserbeans.org/original. Here are some links to get you started: A working rule: http://laserbeans.org/bulat/friends (try adding stuff to break it) Just the username: http://laserbeans.org/bulat Problem #1: http://laserbeans.org/original/bulat/friends/junk/morejunk Problem #2: http://laserbeans.org/original/bulat/ You can see the .htaccess file I'm using on those pages, but I'll paste it in here as well. One thing I suggest is defining strict rules for what constitutes a valid username or action and using those in place of the (.*)s. I used ([a-z0-9]+) as a temporary catch-all, but you might want to adjust that for your application. # .htaccess# For simplicity, I assumed these paths don't conflict with# any files you want to serve.RewriteEngine OnRewriteRule ^([a-z0-9]+)/?$ profile.php?id=$1 [NC,L]RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ profile.php?id=$1&goto=$2 [NC,L]

Bulat Bochkariov at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.