4

I keep seeing the ^ character in RewriteRule statements in a context that doesn't fit with the usage specified in this document about regular expressions.

For example: RewriteRule ^(.*)$ $1.php [L,QSA]

What does it signify?

8

It means "this matches the start of the string". So in your example the rule does the rewrite if there's

  • the start of the string (^)
  • any character (.)
  • any number of the previous character (*)
  • the end of the string ($)

In other words, this whole expression matches any string.

  • Ah, of course. I always forget about the begin and end anchors. – Maxpm Aug 31 '11 at 8:32
  • 2
    .* means 0 or more characters, so a zero length string matches too. – pritaeas Aug 31 '11 at 8:59
  • Thanks @pritaeas for the update. I was doing it from memory. – paulmorriss Aug 31 '11 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.