TakeDown
TakeDown

Reputation: 75

How do websites use different URLs for each page?

I know that you can insert in the URL a variable with GET like this www.website.com/search?q=wow. I am using this method on my website as well. What i don't seem to understand is how site like YouTube use www.youtube.com/user/wow. Do they actually have different files for each user or is it a similar technique?

Upvotes: 0

Views: 76

Answers (1)

blkrt
blkrt

Reputation: 297

Traditionally on Unix systems, the home directory of a particular user can be referred to as ~user/. The module 'mod_userdir' extends this idea to the web by allowing files under each user's home directory to be accessed using URLs such as the following.

http://www.example.com/~user/file.html

For security reasons, it is inappropriate to give direct access to a user's home directory from the web. Therefore, the UserDir directive specifies a directory underneath the user's home directory where web files are located. Using the default setting of Userdir 'public_html', the above URL maps to a file at a directory like /home/user/public_html/file.html where /home/user/ is the user's home directory as specified in /etc/passwd.

There are also several other forms of the Userdir directive which you can use on systems where /etc/passwd does not contain the location of the home directory.

Some people find the "~" symbol (which is often encoded on the web as %7e) to be awkward and prefer to use an alternate string to represent user directories. This functionality is not supported by mod_userdir. However, if users' home directories are structured in a regular way, then it is possible to use the AliasMatch directive to achieve the desired effect. For example, to make http://www.example.com/upages/user/file.html map to /home/user/public_html/file.html, use the following AliasMatch directive:

AliasMatch "^/upages/([a-zA-Z0-9]+)(/(.*))?$" "/home/$1/public_html/$3"

For more information :

https://httpd.apache.org/docs/trunk/urlmapping.html

Upvotes: 1

Related Questions