0
votes

apache mod rewrite is acting weird on me: im trying to redirect this: http://www.website.com/page.php?id=34 to this: http://www.website.com/

using this in the htaccess:

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^page\.php$ "http://www.website.com" [R=301,L]

it works fine, but it also adds the query string to the redirected url:

http://www.website.com/?id=34

how do I remove the query string from the redirected url?

2

2 Answers

3
votes

By default, mod_rewrite won't change the query strings, it'll keep them unchanged and pass them to whatever the new URI is. To remove them, you need to end the new URL with a question mark. You also don't need the quotation marks around it. This should work:

RewriteRule ^page\.php$ http://www.website.com? [R=301,L]
1
votes

i'm not sure if it is going to work but try:

RewriteRule ^page\.php "http://www.website.com" [R=301,L]