So then I tried the following. I put my command ABOVE the Wordpress block. And RewriteEngine On is at the very top as well.: RewriteRule ^index.php?orderby=product(.*)$ http://vanilla.com/shop [R=301,L]
I’m thinking Google is recording that long url after something stripped away index.php from the path.
And even if I do this:
redirect 301 /index.php?orderby=product_cdate&DescOrderBy=ASC&Itemid=159&option=com_virtuemart&page=shop.browse&category_id&manufacturer_id=0&keyword&keyword1&keyword2&limit=5&limitstart=0page%2F2%2Fpage%2F8%2Fpage%2F4%2Fpage%2F2%2Fpage%2F6%2Fpage%2F3%2Fpage/3/ http://vanilla.com/shop
It redirects to /?orderby=product_cdate&DescOrderBy=ASC&Itemid=159&option=com_virtuemart&page=shop.browse&category_id&manufacturer_id=0&keyword&keyword1&keyword2&limit=5&limitstart=0page%2F2%2Fpage%2F8%2Fpage%2F4%2Fpage%2F2%2Fpage%2F6%2Fpage%2F3%2Fpage/3/ http://vanilla.com/shop
IT JUST REMOVES THE INDEX.PHP and doesn’t redirect me anywhere.
I guess the first order of business is to figure out why it’s stripping out index.php from the string. Then try to get it to redirect, but I don’t know. I’m stumped.
There’s a couple problems here. First, the query string will not be in the path that rewrite rules match on. And second, the “?” is special in regular expressions. It means the preceding character is optional.
And you’re absolutely right. One little ? did the trick. Thank you!
Do I have to worry about the L when the important Wordpress rewrite directives follow?
How about this next one? It’s harder.
Suppose we have urls like this:
/index.php?page=shop.product_details&product_id=113&flypage=flypage.tpl&pop=0&option=com_virtuemart&Itemid=159
that should go to pages like this: http://vanilla.com/shop/pure-vanilla-dextrose-powder/
whereby the product id differs and goes to different pages. And there are lots of variations of that url that include product ids. So any variation with a match on product_id=something should all do the same thing.
(Understand I don’t know what I’m doing there. Just printed that to give you the idea.
And it gets trickier because we may have product 113, 114, 115, 116 all now needing to point to the SAME NEW page. Is there a way to combine them into one directive maybe with an “or” statement?
Since there were only about 30 or 40 products to be redirected I have no problem writing a command for each, but if there is a way to combine them, that would be great.
WP protects idiots from their own demise with the <IfModule> wrappers but keeping them in your .htaccess code is TERRIBLY wasteful of the server’s resources (moreso even than WP itself, I believe).
JM’s first response should have been that a RewriteRule can only examine the %{REQUEST_URI} variable which specifically excludes the protocol, domain and query string.
Order: Your SPECIFIC mod_rewrite code must come before the WP code which is very generic - think about the generic code hijacking ALL requests and not giving your code a chance to match.
The Last flag will direct Apache to go institute the redirection and restarts the pass through the mod_rewrite code.
If you do not wish to retain an existing query string, there are two ways to delete it: You’ve discovered the first (using a ? after the redirection - it gets removed automatically so don’t worry about it showing in your links) and creating a new query string.
Making product id redirections is simple - and effective so long at their redirections are to existing web pages (else they’ll be hijacked by WP’s code, too).
You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.
You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.
Unfortunately anyone who learns from this tutorial will have to unlearn some incorrect information later on. I strongly recommend that anyone interested learn from the Apache documentation. That’s where you’ll find the most complete, authoritative, and correct information.
You were closer than you thought so kudos to you as a newbie to mod_rewrite!
Are you on an IIS server or Apache? IIS has its own sets of mod_rewrite emulators one of which is quite different.
On an Apache 2.x server, you can delete the code you had which is colored red and add the blue and it should work for you IF you include this before WP’s code (which will redirect everything).
You may not need it (because of your good start but you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.
If you looked at my signature, you would have seen a mod_rewrite code generator, too. That said, code generators are horrible as there can easily be extenuating circumstances which are outside the scope of the question. For instance, Apache can’t serve [noparse]http://www.dynamictours.co.il/index.php/food-tours[/noparse] (not without Options +MultiViews which I consider a horrible feature - it’ll serve index.php even without the .php file extension) so additional mod_rewrite (or core) code is required. I have a term, “Specificity,” which encompasses the need to fully define the requirements before coding mod_rewrite.