1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

301 If File Not Found

Discussion in 'Apache' started by T0PS3O, Jul 5, 2005.

  1. #1
    I've got my 301 list all set up for the server and software switch (new URLs for all pages) but I was wondering how to capture those potentially forgotten or from deleted pages?

    Is there a way to do something like this in .htaccess (example only, I know it's not the right syntax :) )

    Code (Text):
    1. if(file_not_found($url) === TRUE) { redirect_to_homepage($url); }
     
    T0PS3O, Jul 5, 2005 IP
  2. SEbasic

    SEbasic Peon

    Messages:
    6,318
    Likes Received:
    318
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why would you want to do that?

    You're looking to eradicate all 404's?
     
    SEbasic, Jul 5, 2005 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,220
    Likes Received:
    778
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I just want all link power to go to the homepage instead of to lost pages.
     
    T0PS3O, Jul 5, 2005 IP
  4. fryman

    fryman Kiss my rep

    Messages:
    9,605
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I agree with sebasic, that will only confuse your visitors
     
    fryman, Jul 5, 2005 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,220
    Likes Received:
    778
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It's eiether this quick fix or I'll have to customize 404's. I'd rather do the quick fix now and get a half interested customer lost at the homepage with useful, more or less related material as oppose to a dirty 404 File Not Found and the punter guaranteed to hit the back button.

    We're only talking a small number here so it's not like we'll be causing mass hysteria.
     
    T0PS3O, Jul 5, 2005 IP
  6. nddb

    nddb Peon

    Messages:
    803
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !-U
    RewriteRule ^(.+) http://www.domain.com/

    That MAY work. Basically, -U says (if this is an existing url), !-U says (if this is NOT an existing url)
    then you redirect everything to http://www.domain.com/ (your domain).

    May not work, but isn't hard to try it for a second.
     
    nddb, Jul 5, 2005 IP
  7. SEbasic

    SEbasic Peon

    Messages:
    6,318
    Likes Received:
    318
    Best Answers:
    0
    Trophy Points:
    0
    #7
    personally I wouldn't do it...

    If you start to see a lot of unsuccesful requests for specific pages or files, then by all means add the 301, but to send everything to the index page of the site if a file is not found is a mistake in my opinion.

    Edit - forgot to click submit about half an hour ago :rolleyes:
     
    SEbasic, Jul 5, 2005 IP
  8. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,220
    Likes Received:
    778
    Best Answers:
    0
    Trophy Points:
    0
    #8
    So what would you do?

    Thanks nddb, I'll see if that works as planned.
     
    T0PS3O, Jul 5, 2005 IP
  9. nddb

    nddb Peon

    Messages:
    803
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Most people would probably do custom error pages. Perhaps load a 404 error in the template of the page, if possible. I don't see the harm, especially if it's only a handful of pages, it would be nice to let the user know there was a 404 error, but if you can't do it in a good way, oh well. =)
     
    nddb, Jul 5, 2005 IP
  10. SEbasic

    SEbasic Peon

    Messages:
    6,318
    Likes Received:
    318
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Check the logs for persistent 404's then setup redirects accordingly.

    Otherwise just provide a good 404 page for the user if they can't find what they are looking for...

    Just had an idea for this.........

    What if..

    Someone comes from an SE and gets a 404.
    You then redirect the user based on the search terms they used, to the search results page of your site.

    So I type in "Mouse traps" and your site used to have a page about that, but for whatever reason, it's now not there...

    So you just redirect me to yoursite.com/search.php?query=mouse+traps

    I like that idea :D
     
    SEbasic, Jul 5, 2005 IP
  11. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,220
    Likes Received:
    778
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I like the idea of custom 404's and referal based content but like I said, I need a quick fix for now until the day comes I feel those 'lost' punters are worth more to my business than those who will find us.

    I'll consider all options, thanks for your ideas.
     
    T0PS3O, Jul 5, 2005 IP
  12. nddb

    nddb Peon

    Messages:
    803
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #12
    lemme know if it works, always good to know. =)
     
    nddb, Jul 5, 2005 IP
  13. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,220
    Likes Received:
    778
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I'll e-mail the owner of www.domain.com tomorrow to see how much traffic he got... :)
     
    T0PS3O, Jul 5, 2005 IP
  14. nddb

    nddb Peon

    Messages:
    803
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #14
    lol... well, i don't know your domain, so you gotta switch that part. =)
     
    nddb, Jul 5, 2005 IP