Twitter Like URL but with a @'s?

.htaccess, url

Solution

From my understanding of your question, this should work.

Options +FollowSymLinks

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^@(.+?)$ user.php?u=$1 [NC,L]

It requires you to have a @ before the username and it passes it as a GET variable (u) However, a person can add other characters which could confuse it as a username.

/@username/muffins

But if you want this, and to have pages per username (ie, /@username/info, /@username/about, etc) you can just use the explode() function in PHP.

If you just want it to get the username and nothing else, you can try

RewriteRule ^@([A-Za-z0-9]+)$ user.php?u=$1 [NC,L]

Hope this helps! :)

Problem

I am making a social networking website, and I can't get this done: If the url is `http://url.com/@username`, I want it to show the `http://url.com/user?u=username` page, but show `http://url.com/@username` URL. However, if there is no `@` in the beginning, treat it like a regular URL. This is my `.htaccess` file: ``` Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L] RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^/(\d+)*$ ./user.php?u=$1 ``` The last three lines are what I tried, however that does not work as I wanted it to. I thought it would work because `RewriteRule ^/(\d+)*$` takes any URI after the slash, and rewrites it to `.user.php?u=*`, but that didn't work, so I am looking for some suggestions on what to do next.

Original source