SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2001
    Location
    New York
    Posts
    499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Bizarre 301 redirect issues

    So here is one that has me stumped. I'm trying to redirect posts from an old forum that I've converted from phpbb to vbulletin. In the .htaccess file, I've put in the following:

    Redirect 301 /viewtopic.php?f=11&t=12 http://www.new.com/forum/showthread.php?t=23344

    That doesn't do a thing. If you go to http://www.old.com/viewtopic.php?f=11&t=12 , it simply shows the post on the old site. Now if I enter:

    Redirect 301 / http://www.new.com/forum/

    That will redirect the root directory to the forum directory on the new site properly. What I can't get are the individual pages to work. If I enter the following:

    Redirect 301 / http://www.new.com/forum/
    Redirect 301 /viewtopic.php?f=11&t=12 http://www.new.com/forum/showthread.php?t=23344

    I get page not found errors because the server is looking at the root based redirect and sending me to the new site with the old extension

    http://www.old.com/viewtopic.php?f=11&t=12

    That obviously doesn't exist. Has anyone ever seen a case where redirect is ignoring individual pages?
    Last edited by ScallioXTX; Jan 16, 2012 at 12:57. Reason: delinkified example URLs
    My site for law answers and legal information -- I also buy websites you may wish to sell

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,891
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    IIRC you can't use the query string in Redirect, only complete path URLs.

    If you want to redirect using values in the query string you should use mod_rewrite instead

    Code:
    RewriteEngine On
    RewriteCond %{QUERY_STRING} f=11&t=12
    RewriteRule ^viewtopic.php http://www.new.com/forum/showthread.php?t=23344 [L,R=301]
    HTH
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2001
    Location
    New York
    Posts
    499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks - it doesn't work - and as if it couldn't get weirder.

    In Firefox, Safari and IE it just stays on the old site as if nothing is rewritten. Nothing happens.
    But when I go to Chrome, I get sent to http://www.new.com/forum/viewtopic.php?f=13&t=18
    My site for law answers and legal information -- I also buy websites you may wish to sell

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,891
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    Before you test it, please make sure to empty the cache of your browser and restart it. Browsers cache 301 redirects, so if they have an old redirect stored somewhere they will use that instead of the new one.

    While testing it's better to use 302 redirected (which should not be cached browsers) and then switch to 301 once you've established it works.

    I've just tested the code I showed you, and it works fine here. Could you please post your complete .htaccess?

    Also, which version of Apache are you on, 1.x or 2.x ?
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2001
    Location
    New York
    Posts
    499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks!!!!

    For reasons I cannot explain, after about 2 minutes, whatever it was that was causing the problem just stopped and using your suggestion works although the standard does not.

    Perhaps it was the browser cache? Hard to say because I thought I had IE as autoemptying. Another good one to know after much frustration. Again, many thanks!!
    My site for law answers and legal information -- I also buy websites you may wish to sell

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2001
    Location
    New York
    Posts
    499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One last question if I may - the only thing not redirecting now is the root - I tried doing just a rewrite rule with either /index.php or just a / and neither worked. Is there anything you can suggest that would complement the above for this? (I've actually just purchased the hardcover mod rewrite book just now )
    My site for law answers and legal information -- I also buy websites you may wish to sell

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,891
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    Where should they redirect to? Also, please show the code you wrote
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  8. #8
    SitePoint Evangelist
    Join Date
    Mar 2001
    Location
    New York
    Posts
    499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Where should they redirect to? Also, please show the code you wrote
    Thanks.

    root directory should go to http://www.new.com/forum/

    I tried
    RewriteRule ^/ http://www.thelaw.com/forums/ [R=301,L]
    RewriteRule ^/index\.php http://www.thelaw.com/forums/ [R=301,L]

    and neither worked. The root evidently has both old.com/ and old.com/index.php url to refer to home.

    Again, many thanks!
    My site for law answers and legal information -- I also buy websites you may wish to sell

  9. #9
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,891
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    RewriteRules don't start with a tailing slash (at least, not anymore in Apache 2.x, they used to in 1.x)

    So instead of ^/ it should be ^$ (i.e. empty request, i.e., root), and ^/index\.php should be ^index\.php

    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  10. #10
    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)
    Note: The Redirect statements did not work because (I believe) mod_alias can't look at the query string. That's why Rémon recommended mod_rewrite, the Swiss Army Knife for webmasters.

    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


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
  •