lucy24 - 3:23 pm on Apr 8, 2013 (gmt 0)
$ only means "end of string" in the pattern. (Outside of htaccess it can also mean "end of line" but within htaccess each string is only one line anyway.) In the target it has a different meaning: $1 $2 etc. through $9 means "reuse the captured group".
RewriteRule ^name_([a-z]+)\.html http://www.example.com/newplace/$1 [R=301,L]
request for /name_foobar.html
request for /name_anchor.html
request for /name_ogooglebar.html
request for /name_something-else.html
does not redirect because "something-else" contains a character other than a-z so it does not fit the pattern.
The caret ^ is even worse because it has two different meanings in the pattern (none in the target). By itself it means "beginning of string" but as the first character inside grouping brackets it means "not", so
^[a-z] = string begins with a letter
[^a-z] = anything other than a letter
^[^a-z] = string begins with a non-letter
Can't remember if we have a boilerplate post that lists (a) the characters that have special meaning in Regular Expressions and (b) characters that have special meaning in mod_rewrite and/or apache-in-general (notably ! and space).
RewriteRule ^(name_[0-9]+)\.htm http://www.example.com/reviews/$1.htm [R=301,L]
Then I tried to add a second rule right after the first like so:
RewriteRule ^(spanish/name_[0-9]+)\.htm http://www.example.com/spanish/opiniones/$1.htm [R=301,L]
And then the first stopped to work, and the second is not ok as I got this url: http://www.example.com/spanish/opiniones/spanish/name_2005.htm
You goofed and included "spanish/" in your capture. Fix the parentheses and all should be well.
If the URLs use ".htm" both before and after the redirect, and the filename stays at the end, you may as well include it in the capture.
No reason for the first rule to stop working, though. Are they both anchored as you show them here?
And now go write out the word example in big letters, post it above the computer and memorize the spelling ;)