Forum Moderators: phranque
aaa-bbb-ccc
then the first will return:
$1 = aaa
$2 = bbb
and the second (I think):
$1 = aaa-bbb
$2 = ccc
The above is correct, but actually, there is more to the difference:
(It is difficult to explain, so I may not be explaining the exact matching sequence exactly, but it is close and should give you an idea.)
([^-]+)-([^-]+) = Any one or more characters that is not a - followed by a - followed by one or more characters that is not a -
This pattern will correctly break as soon as it hits the first -, match the - and then break when it hits the second - : the output aaa-bbb would be stored on the first pass.
(.*)-(.*) = 0 or More characters that are not the end of a line, followed by a - followed by 0 or More characters that are not the end of a line.
The first .* will store the entire line, and check for a match to the pattern, because every character is 'not the end of a line' when the store pattern does not match the set pattern, the engine will then 'back-up' until it hits the second - in the pattern, which creates a match for the pattern up to the *second* - then the .* will match the rest of the line.
Output is: aaa-bbb ccc
To get a correct match from .* you would have to use (.*)-(.*)-(.*) which will cause the engine to match (1st .*), back-up (gets to the second -), match (2nd .*), back-up (1st .* gets to the first -), match (2nd .*), back-up (gets the 2nd .* to the second -), match (3rd .*) finally gets to the end of the line.
Conversly:
([^-]+)-([^-]+)-([^-]+) Would match on one pass.
Hope this makes a little sense.
Justin
If I have this url:
[domian.com...]
and wanted to change into:
[domain.com...]
Is this rewrite correct?
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /cars/
RewriteRule ^index/(.*)/(.*)/(.*)\.html$ /search.php?c=$1&s=$2 [L]
Please advise.
RewriteRule ^index/([^/]+)/([^/]+)/([^.]+)\.html$ /search.php?c=$1&s=$2 [L]
But that still doesn't match the description of what you say you want to do.
RewriteRule ^free/search/([0-9])([0-9]{2})\.html /free/search.php?c=$1&s=$2 [L]
You will also need to manually change the URLs on your php-generated pages to the "761.html" form in order for this to work. The client browsers and spiders will then see "761.html" and request it. Your mod-rewrite code will then call search.php with the "7" and "61" extracted from the requested URL and placed into the parameters expected by search.php.
If you want this project to succeed, you'll need to study the documents cited in our forum charter [webmasterworld.com] and in the Apache section of the WebmasterWorld library [webmasterworld.com].
Jim