• [ Pobierz caÅ‚ość w formacie PDF ]

    Yes, unfortunately, the biggest pitfall with this approach is that it breaks your other
    virtual hosts. You need to pick one approach or the other. If you use mod_vhost_alias
    alongside traditional configuration blocks, you are almost certain to
    run into problems.
    It s the  almost certain part that tends to be more than a little confusing. You ll
    encounter some people who will assert most vociferously that  It works for me! and
    they tend to greatly confuse the issue. There are indeed certain circumstances in which
    mod_vhost_alias and regular virtual hosts can happily coexist. However, virtual hosts in
    the same configuration as mod_vhost_alias do tend to be very fragile, and the smallest
    misconfiguration can cause them to do not only incorrect, but sometimes completely
    unpredictable things. So, as much as you or someone else wants to assert that it worked
    for you once and should work for you again, I strongly encourage you to avoid using
    mod_vhost_alias in conjunction with other virtual hosting techniques. It will very likely
    break things.
    Logging
    I ll discuss logging a little later, but it s worth at least mentioning here, as it is a common
    complaint about mod_vhost_alias. All of the virtual hosts log to a single log file. You ll
    have to either put up with that or use one of the techniques described in the  Logging
    for Mass Virtual Hosts section later in this chapter.
    It s Too Inflexible
    Eventually, you ll run up against the fact that mod_vhost_alias is just very inflexible. It
    does not permit per-vhost changes. So, if one of your virtual hosts needs a particular
    change to it, there s no easy way to do it.
    The most common solution to this is to allow the various virtual hosts to modify
    their configuration using .htaccessfiles. You can also modify their configuration using
    blocks in the main configuration file, but, since the goal was to avoid having
    to change the configuration file at all, this is usually undesirable.
    Mass Virtual Hosting with mod_rewrite
    This brings us to the heart of this chapter. Since this is, after all, a book about
    mod_rewrite, it s about time we got around to talking about it.
    Handling mass virtual hosting (or even just a small number of virtual hosts) is, after
    beautifying ugly URLs, the most popular use of mod_rewrite. Fortunately, it s fairly easy
    and well documented.
    5610_c10.final.qxd 1/10/06 1:05 AM Page 105
    CHAPTER 10  % VIRTUAL HOSTS 105
    There are a number of different ways we might go about handling virtual hosts. We re
    going to look at two solutions, each of which approaches the problem slightly differently.
    Rewriting Virtual Hosts
    We ll start with the most common approach, which is to do a simple rewrite to a file path,
    based on the value of the SERVER_NAMEheader. This gives us a rule set like this:
    RewriteEngine On
    RewriteMap lowercase int:tolower
    RewriteRule ^/(.*)$ /www/${lowercase:%{SERVER_NAME}}/docs/$1
    Using this rule set, a request for documents from www.example.comis mapped to the
    directory /www/www.example.com/docs/. This is almost the same directory that we created
    with the mod_vhost_alias configuration, except that the entire hostname is used.
    The RewriteMapis necessary because the hostname might be uppercase or lowercase,
    and we need to make sure that we have only one possible target file path for each request.
    Using the internal rewrite map function tolower, we lowercase the requested hostname
    and rewrite to a file path created using that hostname.
    This approach, as shown here, immediately creates a couple of problems. We ll tackle
    the easier ones first.
    www.example.com works, but example.com Doesn t
    As with mod_vhost_alias, we have the problem where requests for www.example.comwill
    be handled correctly, while requests for example.comwill generate File Not Found errors.
    We want those two hostnames to be treated the same, and this requires a little more
    work. Since mod_rewrite doesn t have an immediate way to pull off the different parts
    of the hostname, we need to do this using RewriteCond.
    Our modified rule set looks like the following:
    RewriteEngine On
    RewriteMap lowercase int:tolower
    RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
    RewriteRule ^/(.*)$ /www/${lowercase:%2}/docs/$1 [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • matkadziecka.xlx.pl