Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RewriteRule ^ - [L] AKA RewriteRule caret dash L

While I could turn on Rewrite Logging and mess with this rule to figure out what it does (if anything), I bet someone already knows. Here's the rule by itself:

RewriteRule ^ - [L]

Here it is in context:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

I guess it means "Match Everything". I'd have thought that "Match Everything" would be a dot to make it more obvious that there is no missing code, and that regexp would error out if the caret was the only thing in it. So I see the outside chance that it means something else.

like image 727
Dave Scotese Avatar asked Jun 25 '13 16:06

Dave Scotese


People also ask

What is RewriteCond and RewriteRule?

There are two main directive of this module: RewriteCond & RewriteRule . RewriteRule is used to rewrite the url as the name signifies if all the conditions defined in RewriteCond are matching. One or more RewriteCond can precede a RewriteRule directive.

What is mod_rewrite C?

The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be used to redirect one URL to another URL, or to invoke an internal proxy fetch.

What is NC in RewriteCond?

NC|nocase. Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear as upper-case or lower-case in the matched URI. In the example below, any request for an image file will be proxied to your dedicated image server.


1 Answers

  • ^ is a somewhat unorthodox way of saying "match anything", just as you say
  • - means "take no action"
  • [L] means "last rule" i.e. stop processing RewriteRules after this point

I assume there are other rules following this one, because this combination of RewriteCond/RewriteRule says that if the current request is for an existing file or directory, mod_rewrite should ignore any subsequent RewriteRules.


Expressed in code, this would be equivalent to:

do_rewrites(req)
{
  if (is_file(req) || is_dir(req))
    return;

  // other rules
  ...
}
like image 178
Martin Avatar answered Oct 13 '22 20:10

Martin