Forum Moderators: phranque

Message Too Old, No Replies

changing page names

mod_rewrite to change page names

         

ssgumby

5:07 pm on Apr 28, 2008 (gmt 0)

10+ Year Member



This is simple im sure, but I cant figure it out.

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

jdMorgan

5:24 pm on Apr 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Query strings are not visible to RewriteRule; Use "RewriteCond %{QUERY_STRING} ^pattern$" to match a query string.

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

ssgumby

12:56 pm on Apr 29, 2008 (gmt 0)

10+ Year Member



Thank you Jim! This cleared things up and works perfectly now.