Forum Moderators: phranque

Message Too Old, No Replies

twitter, myspace style url rewriting

         

eltreno

7:50 pm on May 17, 2009 (gmt 0)

10+ Year Member



What do I need to research to work out how to do the whole

domain.com/someusername

direct to,

domain.com/index.php?username=someusername

Also I take it you need to have a way to not direct centain directoriel like, 'account' etc

is it using .htaccess?

dreamcatcher

6:12 am on May 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, it is htaccess. I`ll move your thread to the Apache server forum where you`ll no doubt get more help.

dc

jdMorgan

5:55 pm on May 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using your example, the basic code would be something like:

RewriteCond $1 !^(index\.php¦robots\.txt¦sitemap\.xml¦labels\.rdf¦w3c/p3p\.xml¦google[0-9a-f]{16}¦y_key_[0-9a-f]{16}\.html¦LiveSearchSiteAuth\.xml)$
RewriteCond $1 !^account/
RewriteRule ^(.*)$ /index.php?username=$1 [L]

As you can see, the list of URL-paths to be excluded gets quite long, and I cannot be at all sure I've covered anywhere near all of the exclusions you'd need.

There are two solutions to avoid having to list *all* URL-paths that must be excluded. One is 'easy' but can be quite inefficient, because it requires two additional calls to the operating system to check for file and directory exists for every request recieved by your server, and this can slow down your server to the point where you will be forced to upgrade your hosting account sooner than normal if you have a successful/busy site:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?username=$1 [L]

A much more efficient plan, from both a URL-rewriting and a site administration standpoint, is to make the "username" URLs unique. Something like:

RewriteRule ^users/(.*)$ /index.php?username=$1 [L]

-or-

RewriteRule ^member-(.*)$ /index.php?username=$1 [L]

With this method, the entire issue of having your usernames 'collide' with physically-existing files or directories is avoided, because all 'username" URLs start with "users/" or "members-" as shown.

Check out the resources cited in our Forum Charter and the example threads in our Forum Library. Links to both of these are at the top of this page.

Jim