scm,
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.
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:
[COLOR="#FF0000"]Options +FollowSymLinks[/COLOR] # should already be in the httpd.conf so this is not (normally) necessary
RewriteEngine on
RewriteRule (.*)/(.*)/$ /state.php?param1=$1
Is $2 a “throw-away”? If so, then why create that variable?
Options +FollowSymLinks
RewriteEngine on
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.
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/(.*)/$ state.php?state=$1
Okay, uses state as a key rather than param1.
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/(.*)/$ /state.php?state=$1
Ditto.
http://whatsmyowncarworth.com/new-york
http://whatsmyowncarworth.com/massachusetts
http://whatsmyowncarworth.com/nevada
http://whatsmyowncarworth.com/test.html
These are your test URIs? What does test.html have to do with your state problem?
RewriteEngine on
RewriteRule ^test\\.html$ test.php [L] # irrelevant to state problem
RewriteRule ^([a-zA-Z_]+)$
state.php?state=$1 [L]
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).
Changing to the one-liner:
RewriteRule ^([a-zA-Z_]+)$ state.php?state=$1 [L]
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 ^(new-york|massachusetts|nevada)$ 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.
Please have a re-read of the Regex section of the tutorial.
Regards,
DK