3

I have this rule in Angularjs app. It work perfectly. But I want to understand one rule which I don't know what it does RewriteRule ^.*$ - [NC,L] #???

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -!f 
RewriteRule ^.*$ - [NC,L] #NC none-case-sensitive, L stop when match
RewriteRule ^(.*) index.html [NC,L] 

Please help me on this rule RewriteRule ^.*$ - [NC,L] I know about the [NC,L] flags but I don't get ^.*$ - especially the empty dash at the end of rule.

1 Answer 1

1
+50

The syntax of the RewriteRule is:

RewriteRule Pattern Substitution [flags]

Your rule is:

RewriteRule ^.*$ - [NC,L]
  • ^.*$ is a perl compatible regular expression where

    • ^ is the start of string
    • . is any character except newline
    • * means 0 or more times
    • $ is the end of string.
  • The substiution is - which means: "no substitution should be performed (the existing path is passed through untouched). This is used when a flag needs to be applied without changing the path."

  • The flags are NC and L, which means:

    • NC: Makes the pattern comparison case-insensitive.
    • L: Stop the rewriting process immediately and don't apply any more rules. Especially note caveats for per-directory and .htaccess context (see also the END flag).

So this rule matches anything, makes no substitution, and stops the rewriting process immediately.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for response. Then, Can I say that the last rule RewriteRule ^(.*) index.html [NC,L] never get match as this rule ^.*$ matches anything?
Yes, the pattern ^.*$ in combination with the flag L, make all subsequent rules not applied.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.