First, the tutorial should have corrected your description as you want mod_rewrite to accept a state and redirect it to state.php with the value of the state in the URI assigned to the state key.
Originally Posted by scm22ri
Note: You can redirect to the preferred (non-servable) URI then back but that's more of an advanced topic. Best to get it right before delving into that, IMHO.
Second, the tutorial described single name states (no spaces) as well as the changes required when there is a space in the state's name (i.e., best to change the link and replace spaces with _'s because %20 is so !@#$ ugly). Also, if you don't want to accept "garbage" as a state name, you really need to create a list of acceptable states (also shown in the tutorial).
Third, your original attempt shows a space between rhode and island but you've shown a hyphen in the link you wanted to use.
Okay, comments on your original code above:
Is $2 a "throw-away"? If so, then why create that variable?
Options +FollowSymLinks # should already be in the httpd.conf so this is not (normally) necessary
RewriteRule (.*)/(.*)/$ /state.php?param1=$1
How is this any different? If you're already in the DocumentRoot (where I like to keep my mod_rewrite code), there is no difference at all.
RewriteRule (.*)/(.*)/$ state.php?param1=$1
Okay, uses state as a key rather than param1.
RewriteRule (.*)/(.*)/$ state.php?state=$1
RewriteRule (.*)/(.*)/$ /state.php?state=$1
These are your test URIs? What does test.html have to do with your state problem?
THIS is what is causing the 500's as there should be no line return after the regex. 500's are almost always the result of syntax errors in code (or the module not being available).
RewriteRule ^test\.html$ test.php [L] # irrelevant to state problem
Changing to the one-liner:
this code WILL work for your second and third test URIs (and the fourth) but not new-york. Note that you've included my preferred _ while the link used a - instead. When you use regex, you should be very specific with your directives. Unfortunately, this will also match "garbage", "nEW_yORK" and a lot of other nonsense. Had you been specific about what your database query is expecting to find, use of
RewriteRule ^([a-zA-Z_]+)$ state.php?state=$1 [L]
WOULD have worked. However, when testing, change your [L] flag to [R=301,L] so you can see the redirection in the URI (and KNOW that your mod_rewrite is working properly) - you can remove the R=301, when you're ready to go live on your website.
RewriteRule ^(new-york|massachusetts|nevada)$ state.php?state=$1 [L]
Please have a re-read of the Regex section of the tutorial.