I am trying to do a 301 re-direct and a re-write my URL parameters in one go. I have been following some answers around here, but can't get it to work. Here is what I tried. Comments indicate what I hope it does, not what it actually does.
RewriteEngine on
# Redirect from "/country.php?country=FR&recipe=Croissant" to "/FR/Croissant"
RewriteCond %{THE_REQUEST} ^country\.php/?country=([A-Z]{2})&recipe=(.+) [NC]
RewriteRule ^/%1/$2 [NE,L,R=301]
# Redirect from "/country.php?country=FR" to "/FR"
RewriteCond %{THE_REQUEST} ^country\.php/?country=([A-Z]{2}) [NC]
RewriteRule ^/%1 [NE,L,R=301]
# Internally map "/FR/Croissant" to "/country.php?country=FR&recipe=Croissant"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/([A-Z]{2})/(.+)/?$ country\.php/?country=$1&recipe=$2 [L]
# Internally map "/FR" to "/country.php?country=FR"
RewriteRule ^/([A-Z]{2})/?$ country\.php/?country=$1 [L]
But this does not work. Nothing happens when I try either of the examples:
/country.php?country=FR&recipe=Croissant stays /country.php?country=FR&recipe=Croissant and /FR/Croissant returns a 404.
I am running this on a subdirectory of a domain (localhost/food/, with localhost/food/index.php and localhost/food/country.php), but the htaccess file is placed in that directory localhost/food/.
What am I doing wrong?