Good day. I noticed a curious thing (I noticed it a long time ago, of course), but now it would be very useful in my project. The essence of the question is this: A good example is vkontakte.ru . For example, a link to a person’s page is created as follows: http://vk.com and character id . Those. in the work it looks like this: http://vk.com/id3864364 The essence of the question: How does the server catch the GET parameter "id3864364"? After all, I do not think that for each account they create their own html (php) page. :)

If you take the simplest WEB server and execute the request, for example, http: // localhost / id12345, the server will complain that there is no page id12345.

    2 answers 2

    In simple cases, a similar result can be achieved by using the mod_rewrite module in the apache server. Of course, this functionality is also supported for other http servers, however, mod_rewrite is something like a “textbook example.”

    The meaning of this module (if quite simply) is to redirect requests of the form http://vk.com/id3864364 to, say, some script http://vk.com/generator.php?id=id3864364 for quite specific rules (rewrite rules).

    Thus, the user who requested the page http://vk.com/id3864364 is given the result http://vk.com/generator.php?id=id3864364 .


    Of course, the power of mod_rewrite does not end with such trivial examples, but this is already a topic for independent study.

    The benefit of materials and examples on the subject abound.

    The fact is that I use nginx to proxify Apache requests.

    C nginx th such things do not roll. It was necessary in a config of a host on nginx to manage with regular expressions. Namely:

      location ~/id(.*)$ { proxy_pass http://10.1.1.4:8021/myhobby/index.php?id=$1; } location / { proxy_pass http://10.1.1.4:8021/myhobby/; } 

    Those. requests like http://mysite.by/id123 are proxied to index.php with the GET ID parameter, in this case, as http://mysite.by/index.php?id=123 Maybe someone will need it :)) ) I have seen many forums, but I haven’t found the answer to this question anywhere.

    • You are generally a strange type. You ask yourself - you answer it yourself. If you're bored, start a blog - stck
    • one
      If you have nginx, then the more correct config will be: rewrite ^ id (. *) $ Index.php? Id = $ 1 last; location / {proxy_pass 10.1.1.4:8021/myhobby ; } - chernomyrdin