user3311045
user3311045

Reputation: 759

How to understand these mod_rewrite logfile entries?

I have the following in the relevant Apache virtual host configuration:

<Directory "/var/www/html/path">
  RewriteEngine on
  RewriteBase /
  RewriteRule ^go\.html$ /out/qs.html?name=value
</Directory>

Here is the content of the qs.html file:

<html>
 <head><title>Query String</title></head>
 <body>
  <h2>Query String</h2>
  <script>
   document.write("<p>Query String: " + window.location.search.substring(1) + "</p>");
  </script>
 </body>
</html>

When I send an http request to the server for /path/go.html (without any appended query string), the document is returned but no query string is seen in the rendering of the qs.html document. I would expect to see the "name=value" query string.

Here is the relevant lines in the logfile with the fluff removed and line numbers added:

1. [perdir /var/www/html/path/] strip per-dir prefix: /var/www/html/path/go.html -> go.html
2. [perdir /var/www/html/path/] applying pattern '^go\\.html$' to uri 'go.html'
3. [perdir /var/www/html/path/] rewrite 'go.html' -> '/out/qs.html?name=value'
4. split uri=/out/qs.html?name=value -> uri=/out/qs.html, args=name=value
5. [perdir /var/www/html/path/] trying to replace prefix /var/www/html/path/ with /
6. [perdir /var/www/html/path/] internal redirect with /out/qs.html [INTERNAL REDIRECT]

Actually lines 1 thru 3 are pretty much what I would expect and if it just stopped there, I think that I would understand. What I don't understand is why it's continuing from that point and what the remaining 3 lines are telling me. Can someone PLEASE help me understand this. I'm tearing my hair out over this one. Thanks.

     ... doug

Upvotes: 1

Views: 53

Answers (1)

Zareef Ahmed
Zareef Ahmed

Reputation: 26

You need to refer to flag character which can be defined in rewrite rules.

Please refer to https://httpd.apache.org/docs/current/rewrite/flags.html

Also, I can see that their is a mistake in your concept, if you are writing a rewrite rule, you can not read the resulting url through javascript which is client side.

If you really wants to do it, you can use R flag, which will redirect, but in that case purpose of re-writing rule will be defeated.

Upvotes: 1

Related Questions