views:

28

answers:

1

Okay, so I have a website where the user can put a search query into a form that uses GET to send the data.

When it gets sent, the url looks like: /recipes.php?query=taco&ingredients=chili
And I would like to rewrite it to look like: /recipes-taco-Ichili.html

So I added the following line to my .htaccess file:

RewriteRule recipes\.php\?query=(.*)&ingredients=(.*)$ /recipes-$1-I$2.html [R]

I was under the impression that this would redirect the user to the masked page, but the url doesn't change.

I have RewriteEngine onand once the url is in the form
/recipes-something-Isomethingelse.html it works fine.

I have done it in the past using php, but it seemed like it would be nice if I could do it with .htaccess.

A: 

You cannot get the query string in RewriteRule:

RewriteCond %{QUERY_STRING} ^query=([^&]*)&ingredients=(.*)$
RewriteRule ^recipes.php$ /recipes-%1-I%2.html [R]
Ignacio Vazquez-Abrams
Now I seem to be getting a 302 error instead.
zipcodeman
That's not an error, that's a redirection.
Ignacio Vazquez-Abrams
Yes, but it doesn't show me the page. It just says 'page found'.
zipcodeman
Okay, so now I'm almost there. It Rewrites it, but it still has the `${QUERY_STRING}` at the end, which makes it loop while redirecting.
zipcodeman
I got it to work, I just needed another RewriteCond to check `${THE_REQUEST}` for recipes.php.
zipcodeman