If I have a htaccess file that has RewriteCond %{HTTP_HOST} in it, what is the HTTP_HOST? This is something I've been struggling to find out. To help me understand, could you tell me, in each example that someone might navigate to, what are the (values/responses (?) of) HTTP_HOST, REQUEST_FILENAME and THE_REQUEST? And what will a Rewrite rule actually rewrite?

  1. http://www.meow.co.uk

  2. https://www.meow.co.uk

  3. http://meow.co.uk

  4. http://www.meow.co.uk/woof ("woof" is a directory)

  5. http://www.meow.co.uk/woof/something.html

  6. http://foo.bar.org.uk/meow ("meow" is the same directory as meow.co.uk)

  7. http://foo.bar.org.uk/meow/woof/something ("something" is the same html file as above)

It seems I can't log what is going on in my htaccess as I don't have access to the Apache config file.


This question was put on hold as being too broad. In trying to find out how to use mod_rewrite, I often come across quite specific questions and answers here and on SO, that might be close to what I want to achieve, but leave me with no greater understanding of what the mod_rewrite variables actually are. Sure, I can figure out what the regular expressions mean, but I don't understand exactly what string they are being executed against. If I knew that, I could probably figure out exactly what I need in my .htaccess, and I'm sure others could too.

So, rant over, let's look at examples 5 and 7 above.

What strings are the result of RewriteCond %{HTTP_HOST}, RewriteCond %{REQUEST_FILENAME} and RewriteCond %{THE_REQUEST} when you're navigating to

http://www.meow.co.uk/woof/something.html and


And, assuming you have a RewriteRule after each RewriteCond, are those same strings what the rewrite rules operate on?

  • Is this really too broad? All I expect is a 7 item long list of results (and I suspect that some items will have the same answers) – binaryfunt Oct 1 '15 at 0:12
  • HTTP_HOST is the hostname the user requests when accessing your site. and a RewriteRule can rewrite any URL. You might want to make your question more specific. – Mike Oct 1 '15 at 2:32
  • @Mike Thanks, from that I was able to look up hostname on Wikipedia to find out that 'Hostnames are composed of series of labels concatenated with dots, as are all domain names. For example, "en.wikipedia.org" is a hostname'. Frustrating that my google searches wouldn't relinquish this sentence – binaryfunt Oct 1 '15 at 11:22
  • 1
    The HTTP_HOST is www.meow.co.uk, meow.co.uk and foo.bar.org.uk. The REQUEST_FILENAME is the absolute filesystem filename of the resource being requested, so we don't know exactly what that would be just by looking at the URL. But for http://www.meow.co.uk/woof/something.html it could be something like /home/user/public_html/woof/something.html. THE_REQUEST is the original request header sent from the client eg. GET /woof/something.html HTTP/1.1. – MrWhite Oct 1 '15 at 16:06
  • 1
    The RewriteRule always works on the requested URL (or the rewritten URL if you have multiple rules). The RewriteCond directive is simply a condition that must be met before the RewriteRule will trigger. A bit like an IF statement... IF (condition, condition, condition) then do the rewrite. – MrWhite Oct 1 '15 at 16:39