Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I wanted to become, how do I do that in .htaccess? I tried something like this, but it didn't work:

RewriteBase /fisher
RewriteCond %{QUERY_STRING} ^id=123$    [NC]
RewriteRule ^/product$  /product/foo    [NC,L,R=301]


NOTE: I do not need to capture the value of the id parameter as I will not use it in the new URL.


RewriteEngine On
RewriteBase /fisher

RewriteCond %{QUERY_STRING} ^id=123 [NC]
RewriteRule ^product/$  /product/foo    [NC,L,R=301]
  1. Showing RewriteEngine and RewriteBase
  2. Remove $ in RewriteCond
  3. Remove / in RewriteRule

When I go to http://localhost/fisher/product/?id=123, nothing happens. The URL remains the same.

share|improve this question

marked as duplicate by Jacob, mdpc, EEAA, Andrew, Ward Apr 9 '13 at 5:17

This question was marked as an exact duplicate of an existing question.

Enable RewriteLog. This will give you more info on what is really happening here. – Krist van Besien Apr 9 '13 at 4:56
Do you want /fisher/product/?id=123 to be redirected, or /product/?di=123 ? your questions is a bit unclear here. Do you have your .htaccess in your webroot, or in a subdir of your webroot? – Krist van Besien Apr 9 '13 at 5:06

I would suggest this. Similar to what you have, but with some subtle differences. Namely no $ after id=123 in the RewriteCond and adding a / after ^product in the RewriteRule:

  RewriteCond %{QUERY_STRING} ^id=123 [NC]
  RewriteRule ^product/$ /product/foo [NC,L,R=301]
share|improve this answer
I see why you removed the $; it makes the regex less specific. I don't see why you added a / only; perhaps a /? (optional) might be better? In any case, it didn't work for me. My actual URL is this: localhost/fisher/product/?id=123. Does the fisher (my project name) affect anything? – snoopy76 Apr 8 '13 at 22:43
This should work, however I would not use R=301 while testing. 301 means "redirect permanent" which means that the next time your browser requests this resource it will do the redirect itself, without anything happening on the server. Use R=302. – Krist van Besien Apr 9 '13 at 5:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.