Hello, What's wrong in the following rewrite code: RewriteRule ^dir/page/get.php?id=7785&title=newpr$ http://www.newdomain.org/page7785/ [R=301,L] Code (markup): I want to 301 redirect "http://domain.com/dir/page/get.php?id=7785&title=newpr" (this is not a real page) to "http://www.newdomain.org/page7785/" It didn't work. Even when I used Redirect 301 instead of the mod_rewrite rule it didn't work either. I guess the problem is with the "?" in the first part (the redirected URL). How can I do it?
OK, I got this: RewriteCond %{QUERY_STRING} ^id\=7785\&title\=newpr$ RewriteRule ^dir/page/get.php$ http://www.newdomain.org/page7785/? [R=301,L] Code (markup): The above worked just fine, but my question is: If I remove the "?" from the end of "http://www.newdomain.org/page7785/" in the second line it would attach ?id=7785&title=newpr to the new URL so it would redirect to "http://www.newdomain.org/page7785/?id=7785&title=newpr" but when I add the "?" after the target URL in the second line (as it appears above) it would redirect to "http://www.newdomain.org/page7785/" and NOT "http://www.newdomain.org/page7785/?" but why so? what does the "?" at the end of the target URL mean?
It means you're overwriting the query string (i.e. everything after the ? in a URL) - by default, if there is no query string specified in the destination, it will keep the query string from the original request when rewriting. RewriteRule page.html page.php page.html?pie=good -> page.php?pie=good If you do specify a query string in your destination, this will overwrite the original. RewriteRule page.html index.php?requested=page.html page.html?pie=good -> index.php?requested=page.html If you want to add to the query string so original data is not lost, you use the QSA flag (query string append): RewriteRule page.html index.php?requested=page.html [QSA] page.html?pie=good -> index.php?requested=page.html&pie=good And if you need to remove the query string all together, just overwrite it with a blank string by sticking a ? onto the end of the destination: RewriteRule page.html index.php? page.html?pie=good -> index.php