Forum Moderators: phranque

Message Too Old, No Replies

Difference Between $0 and $1

         

HoboTraveler

5:09 am on Dec 31, 2008 (gmt 0)

10+ Year Member



Hello,

I was wondering which of these is the best to use?

What is the difference between the $0 and $1 although both work okay?

Example One:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ [whateverdomain.com...] [L,R=301]
Note the $0 after the .com

Example Two:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ [whateverdomain.com...] [L,R=301]
Note the $1 after the .com

Example Three:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^whateverdomain\.com$ [NC]
RewriteRule ^(.*)$ [whateverdomain.com...] [R=301,L]

phranque

11:51 am on Dec 31, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



$1 = the first captured group
$0 = the entire matched pattern

for example, if the pattern was:
^prefix(.*)$
then you might get the following results:
$1 = "foo"
$0 = "prefixfoo"

in your pattern, $1 = $0

i would use the following:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

otherwise you won't solve the junk.example.com or www.junk.example.com problems.