"RewriteRule ^" means?

New to mod_rewrite? This is a good place to start.

"RewriteRule ^" means?

Postby marcelloma » Tue Sep 22, 2009 12:51 pm

This code
Code: Select all
RewriteCond %{HTTP_HOST} !^(www\.) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


adds the www. to a domain, but..what does the "^" mean after RewriteRule ?
marcelloma
 
Posts: 9
Joined: Sat Sep 12, 2009 4:14 am

Postby richardk » Wed Sep 23, 2009 9:40 am

It is an anchor. It matches the beginning of the URL (or the relative part of the URL). So ^a will match /a but not /1a.

In this case, as there is nothing after the ^, it will match anything (like .*) because there is always something (even an empty string/URL) to match.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 36 guests

cron