yarek
yarek

Reputation: 12054

what is the '-' (minus sign) for RewriteRule?

I have that rule in the .htaccess.

RewriteRule ^(.+)\.([0-9a-zA-Z]+)$ - [L,NC]

I don"t understand what is the "-" (the minus sign) for, just begin the [L,NC]

$ - [L,NC]

Upvotes: 1

Views: 2064

Answers (2)

Michael Berkowski
Michael Berkowski

Reputation: 270657

From the Apache mod_rewrite docs:

  • (dash) A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.

Effectively it means to take no action when that input URL pattern is matched. Following that with [L] makes sure no subsequent matches will be performed so the input URL is used "as-is". This can be used to exempt one specific pattern from being rewritten when it would otherwise be matched by a more general pattern.

You won't see rules like the one in question too frequently, because it is usually possible to achieve the same result by reordering the RewriteRule, or by modifying the more general matching pattern so it doesn't match the exempt one to begin with.

Upvotes: 5

MrTux
MrTux

Reputation: 34002

A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path. (http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule)

In combination with the L flag this indicates that these URLs should be processed without transformation and no other rules should be applied.

Upvotes: 1

Related Questions