SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 redirect for old dynamic index.php urls to Wordpress doesn't work

    Getting a lot of server errors in my webmaster tools logs for these:

    http://www.vanilla.com/?orderby=prod...%2F2%2Fpage/2/

    I just want all the ones that start with orderby=product to point Google to:

    http://vanilla.com/shop

    I tried:
    RewriteRule ^\?orderby=product(.*)$ http://vanilla.com/shop [R=301,L]

    (It breaks if I take out the \ before the ?) But that didn't work. It redirects me to the blog page.


    Maybe part of the problem is this is a Wordpress site using permalinks and using this in the .htaccess:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    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.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    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.

    This is untested, but try something like this:

    RewriteCond %{QUERY_STRING} ^orderby=product
    RewriteRule ^$ http://vanilla.com/shop [R=301,L]
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Jeff. That's a step forward. It redirects to:

    http://vanilla.com/shop/?orderby=pro...F3%252Fpage/3/

    but only if I leave ,L in there. Take that out and there is no effect. It is being trumped by what follows I guess, like this.

    RewriteCond %{QUERY_STRING} ^orderby=product
    RewriteRule ^$ http://vanilla.com/shop [R=301]

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    what I want is to get rid of the query string entirely so it just goes to http://vanilla.com/shop

    or maybe I should just noindex those. hmmm. ?? That's a thought too.

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    One extra question mark should clear that up.

    RewriteCond %{QUERY_STRING} ^orderby=product
    RewriteRule ^$ http://vanilla.com/shop? [R=301,L]
    "First make it work. Then make it better."

  5. #5
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    How do you write that to work:
    RewriteCond %{QUERY_STRING} [product_id=113]
    RewriteRule [$] http://vanilla.com/shop/pure-vanilla-dextrose-powder [R=301,L]

    (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.

    Thanks.

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    k&m,

    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.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    ...keeping [<IfModule> wrappers] in your .htaccess code is TERRIBLY wasteful of the server's resources (moreso even than WP itself, I believe).
    Wow. Actually, no. Not even close.

    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.
    "First make it work. Then make it better."

  8. #8
    SitePoint Member
    Join Date
    May 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey

    i am trying to redirect my old url to the new one:

    http://www.dynamictours.co.il/Front/...s.asp?id=42498
    to
    http://www.dynamictours.co.il/index.php/food-tours

    i tried this:

    Code:
    RewriteCond %{QUERY_STRING} id=42498
    RewriteRule \/Front/Pages/pages.asp http://www.dynamictours.co.il/index.php/food-tours? [R=301]
    it's not working.

    somebody know how to make it right?
    and how much time it's take to apply rewrite like this (if it's correct)?

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    liorsi,

    Quote Originally Posted by liorsi View Post
    hey

    i am trying to redirect my old url to the new one:

    http://www.dynamictours.co.il/Front/...s.asp?id=42498
    to
    http://www.dynamictours.co.il/index.php/food-tours

    i tried this:

    Code:
    RewriteCond %{QUERY_STRING} id=42498
    RewriteRule \/^Front/Pages/pages\.asp http://www.dynamictours.co.il/index.php/food-tours? [R=301,L]
    it's not working.

    somebody know how to make it right?
    and how much time it's take to apply rewrite like this (if it's correct)?
    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.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    liorsi,



    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.

    Regards,

    DK
    That should work for you, but is it does'nt work, check my signature for easy rewrite generator

  11. #11
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    551,

    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 http://www.dynamictours.co.il/index.php/food-tours (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.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •