SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    WaterGlobe
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    404 error and redirection

    We encountered "File does not exist" problem after we changed the software name from "software_old.exe" to "software_new.exe", then the http request for the file at "www.my_site.com/download/software_old.exe" always cause 404 error.

    Is it possible to redirect the request for "www.my_site.com/download/software_old.exe" to "www.my_site.com/download/software_new.exe"? i.e. user type in address bar "www.my_site.com/download/software_old.exe", he get "www.my_site.com/download/software_new.exe"

    Thanks for help!

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,168
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    If you have access to a .htaccess file, you can force a redirect, like so:

    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^.*$
    RewriteRule ^download/software_old.exe$ http://www.my_site.com/download/software_new.exe [R=301,L]

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Good response, Ralph, except:

    1. You don't need the RewriteCond

    2. mod_rewrite is NOT the correct tool to use for a simple redirect like this.

    Use:
    Code:
    Redirect 301 /download/software_old.exe /download/software_new.exe
    The reason for this is that mod_alias is a part of Apache's core so it doesn't need to be loaded nor does it have to go off and load the regex engine, too, i.e., it is much faster.

    The first thing to learn about mod_rewrite is when NOT to use this POWERFUL tool.

    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

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,168
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Great, thanks David. I'm really keen to learn something about this area, as it's a big world of mystery to me at the moment. I've started to read your wonderful sticky thread, which provides a great introduction, I must say.

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    WaterGlobe
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for help. I add Redirect 301 command in .htaccess file, now it works.

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Thank you, Ralph, and you're welcome, farmer!

    mod_rewrite is a subset of regex made "easy" by "one line" variables that it can access. Where it gets "difficult" is in imagining what can be accomplished with it - better yet, what CAN'T be done with it! As you showed, Ralph, it can do what other tools can do, too, so it's quite a POWERFUL (and useful) tool!

    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 Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,276
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    One of the reasons I went ahead and paid for The Definitive Guided to Apache mod_rewrite by Bowen is because he's got a section all about when not to use it : )


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
  •