TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   domain/user/usename (http://www.talkphp.com/absolute-beginners/3977-domain-user-usename.html)

hello-world 02-14-2009 10:07 AM

domain/user/usename
 
some website like youtube and myspace they provide to every user a link like domain/username. Do they create for each users a directory ?

Scottymeuk 02-14-2009 01:40 PM

Its called mod_rewrite. You use a .htaccess file to rewrite the url. For example:

The raw php URL will look like:

Code:

http://example.com/?user=Scottymeuk
But with the following mod_rewrite code in a .htaccess file (In the root):

Code:

RewriteEngine on
RewriteRule user/(.*)/$ /?user=$2


It will turn out like:

Code:

http://example.com/user/Scottymeuk
So overall, they are not real directories, they are actually getting the information from the database using php but its being rewrote using a .htaccess file.

Please note: I have not tested this code.

Krik 02-14-2009 11:51 PM

You should write a tutorial.

For all the mod rewrite tutorials I have read that is the first one that I could clearly follow. Going to have to go change my rewrite rules.

Village Idiot 02-14-2009 11:56 PM

Quote:

Originally Posted by Krik (Post 21811)
You should write a tutorial.

For all the mod rewrite tutorials I have read that is the first one that I could clearly follow. Going to have to go change my rewrite rules.

If you do not know regular expressions, thing will be hard.

Wildhoney 02-15-2009 01:51 AM

What are your current rewrite rules, Krik, out of curiosity?

Scottymeuk 02-15-2009 03:05 PM

You may also want to change the mod_rewrite code I gave you a bit for validation as at the moment any characters can be used in the URL but you only want to allow alphanumeric chars.

kokjj87 02-16-2009 05:22 AM

Here is one good tutorial for you:
http://www.addedbytes.com/apache/url...for-beginners/


All times are GMT. The time now is 02:11 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0