Forum Moderators: phranque
If I have a page products.php?cat=25 and I want to redirect that page to mywidgets.php, what do I need in my rewrite rule?
I have tried this, but it doesnt work for me.
RewriteRule ^products\.php?cat=25$ [somewidgetsstore.com...] [R=301]
products.php?cat=25 is currently indexed in google and has the exact same content as mywidgets.php, so that is why I want the redirect.
Any ideas?
thanks
To clarify: Given the browser request, "GET /foo.php?bar=3 HTTP/1.1", RewriteRule sees only the URL-path "foo.php" and %{QUERY_STRING} would contain "bar=3". This is because "bar=3" is not part of the URL; It is data attached to the URL to be passed to the resource located by that URL.
To clear the current query string when you rewrite the URL, append a "?" to the substitution URL in your RewriteRule. This "?" is a mod_rewrite 'token' and will not actually appear in the rewritten URL.
Always use the [L] flag on your rules, unless you have a very good reason not to do so.
As always, see the Apache mod_rewrite documentation for details.
Jim