| Chris Morris 2004-06-01, 5:03 pm |
| challisc@hotmail.com (Chris Challis) writes:
> Why the need for $1 in the substitutions section.
>
> RewriteRule ^/somepath(.*) /otherpath$1
>
> results in a URL of something like /otherpath/pathinfo
>
> What is the $1 doing? $ is seemingly an end of line marker. What
> does the 1 do? Can I use other integeres there?
'$' is end of line
'$1' is contents of first sub-expression - the '(.*)' in the source.
So /somepath/foo -> /otherpath/foo ($1 = '/foo')
/somepaths -> /otherpaths ($1 = 's')
You can use more
RewriteRule ^/([a-z]+)/([a-z]+)/ /$2/$1/
does
/a/b/ -> /b/a/ ($1 = 'a', $2 = 'b')
/part/sub/ -> /sub/part/ ($1 = 'part', $2 = 'sub')
/a/20/ -> /a/20/ (pattern doesn't match)
Look for a regular expressions tutorial.
--
Chris
|