Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Useful: mod_rewrite Cheat Sheet by DaveChild at addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet – Anthony Hatzopoulos Jul 26 '12 at 13:49
The usage in the linked document is the same with mod_rewrite (the RewriteRule pattern). However, regex in Apache config files don't use delimiters. – w3dk Oct 31 '15 at 23:03
up vote 8 down vote accepted

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.

share|improve this answer
Ah, of course. I always forget about the begin and end anchors. – Maxpm Aug 31 '11 at 8:32
.* 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 posting your answer, you agree to the privacy policy and terms of service.

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