How to make a separate page for each user on the site? For example mysite.ru/vasiya? I used to do the type: ... / user.php? Id = vasiya. How to make ala contact?) Is this a trick with htmlaccess? there can be no separate file for each user .... thanks in advance!
- 2127.0.0.1/trol = 127.0.0.1/user.php?id=trol => RewriteRule ^ ([0-9a-zA-Z] +) $ user.php? Id = $ 1 - Ilyushka Ovchinnikov
- 3Using mod_rewrite translates request addresses to the server. For example, everything that comes after id will be passed as a parameter to another script, when converting id1234 to userInfo.php? Id = 1234 as in the comment @ Ilyushka Ovchinnikov - ReinRaus
- one@ Ilyushka Ovchinnikov, by the way, this is called CNC (human readable URL). - Nofate ♦
|
2 answers
.htaccess
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [L] index.php
<? if(isset($_SERVER['REQUEST_URI'])) { if(preg_match('#id(\d+)#i',$_SERVER['REQUEST_URI'],$matches)) { print_r($matches); } } |
About vk.com/id*** : there is not Apache with .htaccess , but nginx, and the config looks something like this:
server { server_name vk.com; ... rewrite ^/id(\d+)$ /controllers/id.php?id=$1; rewrite ^/([a-zA-Z\.\-]+)$ /controllers/nickname.php?nickname=$1; } More about rewrite in nginx.
- VK.COM uses Apache! Only he acts as a back-end server. In the role of the Front-End, as you rightly said, NGINX. - Free_man am
- @Dexter: proof? Apache headers are not seen. Server nginx / 1.2.1 X-Powered-By PHP / 5.3.3-7 + squeeze3 - Sergiks
- but it seems to me that it is not the essence of what VC actually uses. The author cited the addresses for example only, and he most likely only learn web programming, which means most likely he uses a bunch of PHP + Apache. - ReinRaus
|