Hướng dẫn xử lý lỗi 404 (Page Not Found) trong Java và PHP

Written by IT Phú Trần on 18/05/2017 in KINH NGHIỆM LẬP TRÌNH and LẬP TRÌNH JAVA and LẬP TRÌNH WEB VỚI JSP/SERVLET with 188 comments.

Khi bạn vào một website nào đó, hoặc truy cập vào một link nào đó sau đó kết quả bạn nhận được là error 404 (Page Not Found).Đây là một trong những lỗi thường gặp khi chúng ta lập trình và chạy website trên server.Vậy 404 là gì và cách xử lý lỗi như thế nào? Hay nói cách khác trong bài này tôi sẽ hướng dãn các bạn hiểu và xử lý được lỗi 404 (Page Not Found) trong Java và PHP.

Trong bài này, nói riêng là Java nhưng các bạn khác ở tất cả các ngôn ngữ lập trình như Java, PHP, .Net…đều đọc được cả nhé.

Error 404 (Page Not Found) là gì?

Hướng dẫn xử lý chuyển hướng khi bị lỗi 404 (Page Not Found) trong Java

Lỗi 404 là một mã trạng thái HTTP với mục đích thông báo bạn đang cố gắng truy cập đến một trang web mà không thể tìm thấy máy chủ của website này. Lỗi “404 Not Found” thường xuất hiện đối với các website cá nhân. 

 Một số trường hợp xảy ra lỗi Error 404 (Page Not Found)

Ở đây, tôi sẽ liệt kê một số trường hợp xảy ra lỗi này :

1.Khi lập trình, có thể điều hướng sai đường dẫn url dẫn tới việc lỗi 404 – Không tìm thấy trang.

2.Người dùng cố tình nhập vào địa chỉ url không chính xác.

Cách khắc phục lỗi Error 404

Rất đơn giản, khi truy cập vào một link url nào đó mà không có chúng ta có thể chuyển hướng đến một trang nào đó bất kỳ trong trang web để tránh trường hợp hiển thị lỗi này trên trình duyệt.

Hướng dẫn xử lý lỗi 404 (Page Not Found) trong Java và PHP
Hướng dẫn xử lý lỗi 404 (Page Not Found) trong Java và PHP

Ví dụ với Java :

Trong đó :

Với PHP chúng ta có thê config trong file htaccess như sau:

404_redirect.php

Lời kết

Như các bạnt thấy rằng, lỗi 404 đây là một trong những lỗi thường gặp nhất. Cách xử lý tùy ngôn ngữ nhưng ý nghĩa là không tìm thấy trang tất nhiên sẽ có nhiều cách xử lý. Nhưng trong bài tôi đang xử lý chuyển hướng đến một trang nào đó trên website.

Nếu cảm thấy bài này, vui lòng chia sẻ để mọi người cùng đọc nhé! Cảm ơn bạn, chúc bạn học tốt.

 

188 Responses to “Hướng dẫn xử lý lỗi 404 (Page Not Found) trong Java và PHP

  1. Howdy! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to get my blog to
    rank for some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Cheers!

  2. I think this is one of the most important info for me.

    And i am glad reading your article. But want to remark on some general things, The web
    site style is ideal, the articles is really excellent : D.
    Good job, cheers

  3. Hurrah, that’s what I was exploring for, what a stuff! present here at this website, thanks admin of this web site.

  4. Wonderful items from you, man. I’ve take note your stuff prior to and you are simply extremely great.

    I really like what you have received here, certainly like what you
    are stating and the way by which you say it. You make it entertaining and you still take care of to keep it
    smart. I cant wait to read far more from you. This is actually a wonderful website.

  5. Oh my goodness! Awesome article dude! Many thanks, However I am encountering difficulties with your RSS.

    I don’t know the reason why I can’t join it. Is there anyone else getting similar RSS problems?
    Anyone who knows the solution can you kindly respond? Thanks!!

  6. I like the valuable information you provide in your articles.
    I will bookmark your blog and check again here frequently.
    I’m quite sure I will learn plenty of new stuff right here!
    Good luck for the next!

  7. Awesome blog! Do you have any tips and hints for aspiring writers?
    I’m hoping to start my own blog soon but I’m a little lost on everything.

    Would you propose starting with a free platform like
    Wordpress or go for a paid option? There are so many choices out there that
    I’m totally overwhelmed .. Any ideas? Thank you!

  8. I have learn several good stuff here. Certainly price bookmarking for revisiting.

    I surprise how a lot attempt you place to create this type of
    fantastic informative web site.

  9. I just want to tell you that I’m new to blogging and really loved you’re blog. Probably I’m going to bookmark your blog . You actually have really good well written articles. Appreciate it for revealing your web-site.

  10. I have observed that in the world of today, video games are the latest phenomenon with kids of all ages. There are times when it may be out of the question to drag your family away from the activities. If you want the very best of both worlds, there are plenty of educational gaming activities for kids. Interesting post.

  11. Spot i’ll carry on with this write-up, I really think this site requirements considerably more consideration. I’ll more likely be again to study considerably more, appreciate your that info.

  12. I loved as much as you will receive carried out right here. The sketch is attractive, your authored material stylish. nonetheless, you command get got an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly very often inside case you shield this increase.

  13. A further issue is that video games are usually serious in nature with the key focus on studying rather than amusement. Although, we have an entertainment element to keep your children engaged, just about every game will likely be designed to work towards a specific group of skills or programs, such as instructional math or scientific disciplines. Thanks for your write-up.

  14. I’ve been surfing online more than three hours today, yet I never found any interesting article like yours. It?s pretty worth enough for me. Personally, if all site owners and bloggers made good content as you did, the net will be a lot more useful than ever before.

  15. A motivating discussion is worth comment. I think that you ought to write more about this topic, it might not be a taboo subject but generally people don’t talk about such subjects. To the next! Many thanks.

  16. An impressive share! I’ve just forwarded this onto a friend who was doing a little homework on this. And he actually bought me lunch because I found it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanks for spending some time to discuss this topic here on your blog.

  17. The next time I read a blog, Hopefully it does not disappoint me as much as this one. I mean, Yes, it was my choice to read, however I genuinely believed you’d have something interesting to say. All I hear is a bunch of moaning about something that you could possibly fix if you weren’t too busy seeking attention.

  18. Aw, this was a very good post. Finding the time and actual effort to make a top notch article… but what can I say… I hesitate a lot and never seem to get anything done.

  19. Greetings! Very useful advice in this particular post! It’s the little changes that will make the largest changes. Thanks a lot for sharing!

  20. You’ve made some really good points there. I checked on the web for additional information about the issue and found most people will go along with your views on this website.

  21. Excellent blog you’ve got here.. It’s difficult to find quality writing like yours nowadays. I really appreciate people like you! Take care!!

  22. I blog frequently and I seriously appreciate your content. This article has truly peaked my interest. I will book mark your website and keep checking for new information about once per week. I subscribed to your RSS feed too.

  23. Good post. I learn something new and challenging on sites I stumbleupon everyday. It will always be useful to read through content from other authors and practice something from other sites.

  24. The next time I read a blog, Hopefully it won’t disappoint me just as much as this particular one. After all, Yes, it was my choice to read, nonetheless I genuinely thought you would have something helpful to talk about. All I hear is a bunch of crying about something that you can fix if you were not too busy looking for attention.

  25. That is a very good tip especially to those new to the blogosphere. Simple but very accurate information… Thank you for sharing this one. A must read article.

  26. After checking out a few of the blog posts on your blog, I truly like your technique of blogging. I saved as a favorite it to my bookmark site list and will be checking back soon. Please visit my website too and tell me how you feel.

  27. After exploring a few of the blog posts on your website, I really appreciate your way of writing a blog. I saved it to my bookmark webpage list and will be checking back in the near future. Please check out my website too and let me know how you feel.

  28. I really love your site.. Excellent colors & theme. Did you build this web site yourself? Please reply back as I’m hoping to create my own site and would like to learn where you got this from or what the theme is named. Thanks!

  29. I would like to thank you for the efforts you’ve put in writing this blog. I’m hoping to view the same high-grade content from you in the future as well. In fact, your creative writing abilities has encouraged me to get my own site now 😉

  30. Faytech North America is a touch screen Manufacturer of both monitors and pcs. They specialize in the design, development, manufacturing and marketing of Capacitive touch screen, Resistive touch screen, Industrial touch screen, IP65 touch screen, touchscreen monitors and integrated touchscreen PCs. Contact them at http://www.faytech.us, 121 Varick Street, New York, NY 10013, +1 646 205 3214.

  31. Good post. I learn something new and challenging on blogs I stumbleupon every day. It’s always useful to read articles from other writers and practice something from their web sites.

  32. This website definitely has all of the information and facts I wanted about this subject and didn’t know who to ask.

  33. After looking at a handful of the blog posts on your blog, I honestly appreciate your technique of writing a blog. I saved as a favorite it to my bookmark website list and will be checking back soon. Take a look at my web site as well and let me know how you feel.

  34. Hello, I do think your web site could be having internet browser compatibility problems. When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping issues. I just wanted to provide you with a quick heads up! Apart from that, fantastic site!

  35. Howdy! I simply wish to offer you a big thumbs up for the great info you have right here on this post. I will be coming back to your blog for more soon.

  36. Howdy! This blog post could not be written any better! Looking through this article reminds me of my previous roommate! He continually kept preaching about this. I most certainly will forward this post to him. Pretty sure he will have a good read. Many thanks for sharing!

  37. Greetings! Very useful advice within this post! It’s the little changes that produce the biggest changes. Thanks a lot for sharing!

  38. Sapid Agency is a Search Engine Optimization company in New York City that provides SEO Services. Their proprietary SEO strategies help struggling websites and aspiring business owners to rank their websites higher in multiple search engines like Google , Yahoo and Bing. They provide local and gmb map ranking for businesses in NYC and many other local areas. Find more at https://www.sapidagency.com/ @ 145 E 57TH NEW YORK, NY 10022, USA, +1 971 341 5608 USA

  39. Greetings! Very useful advice within this article! It is the little changes that make the most important changes. Thanks for sharing!

  40. The very next time I read a blog, I hope that it won’t fail me just as much as this one. I mean, I know it was my choice to read through, however I truly thought you would probably have something useful to say. All I hear is a bunch of crying about something that you could possibly fix if you were not too busy seeking attention.

  41. I’m amazed, I have to admit. Rarely do I come across a blog that’s both educative and amusing, and without a doubt, you’ve hit the nail on the head. The problem is something that too few people are speaking intelligently about. Now i’m very happy I found this during my search for something relating to this.

  42. I blog frequently and I genuinely thank you for your content. This article has really peaked my interest. I am going to book mark your blog and keep checking for new information about once a week. I subscribed to your RSS feed as well.

  43. Good post. I learn something totally new and challenging on blogs I stumbleupon everyday. It’s always useful to read through articles from other authors and practice something from other web sites.

  44. Hi there! This post could not be written much better! Reading through this article reminds me of my previous roommate! He continually kept preaching about this. I will send this post to him. Fairly certain he will have a good read. Thanks for sharing!

  45. After exploring a few of the articles on your web page, I honestly like your technique of writing a blog. I book marked it to my bookmark site list and will be checking back in the near future. Please check out my website as well and tell me how you feel.

  46. This is a great tip especially to those new to the blogosphere. Simple but very precise info… Thank you for sharing this one. A must read post.

  47. Greetings, I do think your web site may be having internet browser compatibility problems. When I look at your web site in Safari, it looks fine however, when opening in IE, it has some overlapping issues. I merely wanted to give you a quick heads up! Besides that, fantastic blog.

  48. Can I simply say what a comfort to find somebody who genuinely understands what they’re talking about on the web. You certainly know how to bring a problem to light and make it important. More people should check this out and understand this side of your story. I was surprised you aren’t more popular since you definitely possess the gift.

  49. Hi, I do believe this is an excellent blog. I stumbledupon it 😉 I am going to come back yet again since i have bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to help other people.

  50. Good post. I learn something new and challenging on blogs I stumbleupon every day. It’s always interesting to read through articles from other writers and practice a little something from their websites.

  51. Hello, I do believe your website could be having browser compatibility problems. When I take a look at your blog in Safari, it looks fine however when opening in Internet Explorer, it’s got some overlapping issues. I merely wanted to give you a quick heads up! Apart from that, great site!

  52. Good day! I simply want to offer you a big thumbs up for the great info you have here on this post. I will be coming back to your website for more soon.

  53. Good web site you have here.. It’s hard to find high-quality writing like yours nowadays. I seriously appreciate individuals like you! Take care!!

  54. I’d like to thank you for the efforts you’ve put in penning this website. I am hoping to view the same high-grade content from you later on as well. In truth, your creative writing abilities has motivated me to get my own, personal site now 😉

  55. Hmm it seems like your site ate my first comment (it was extremely long) so I guess I’ll just
    sum it up what I submitted and say, I’m thoroughly enjoying your blog.

    I as well am an aspiring blog writer but I’m still new
    to everything. Do you have any helpful hints for
    rookie blog writers? I’d really appreciate it.

  56. Oh my goodness! Incredible article dude! Thank you so much, However I am going through issues with your RSS. I don’t understand the reason why I am unable to subscribe to it. Is there anybody having similar RSS problems? Anyone who knows the solution can you kindly respond? Thanx!

  57. Good post. I learn something totally new and challenging on sites I stumbleupon every day. It will always be helpful to read articles from other writers and use something from their sites.

  58. An outstanding share! I have just forwarded this onto a coworker who has been doing a little research on this. And he in fact bought me breakfast simply because I found it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending time to discuss this matter here on your internet site.

  59. Great site you have here.. It’s hard to find excellent writing like yours nowadays. I truly appreciate people like you! Take care!!

  60. This site really has all of the info I needed concerning this subject and didn’t know who to ask.

  61. Good post. I learn something totally new and challenging on websites I stumbleupon everyday. It’s always exciting to read content from other writers and practice something from other websites.

  62. It’s a pity you don’t have a donate button! I’d
    most certainly donate to this excellent blog! I suppose for now i’ll settle for bookmarking and adding your
    RSS feed to my Google account. I look forward to brand new updates and will share this website with my Facebook group.
    Chat soon!

  63. The very next time I read a blog, Hopefully it won’t disappoint me as much as this particular one. I mean, Yes, it was my choice to read, however I genuinely thought you would have something interesting to say. All I hear is a bunch of moaning about something that you can fix if you were not too busy searching for attention.

  64. I really hope to tell you that I am new to having a blog and absolutely cherished your review. Probably I am most likely to save your blog post . You absolutely have wonderful article material. Get Pleasure From it for telling with us your current internet site report

  65. I blog frequently and I genuinely appreciate your content. This great article has really peaked my interest. I will take a note of your site and keep checking for new information about once a week. I subscribed to your RSS feed too.

  66. Spot on with this write-up, I honestly feel this website needs a great deal more attention. I’ll probably be back again to read through more, thanks for the info!

  67. Greetings! Very useful advice within this article! It’s the little changes that will make the most important changes. Many thanks for sharing!

  68. The next time I read a blog, I hope that it does not fail me just as much as this one. I mean, I know it was my choice to read, however I actually believed you’d have something interesting to talk about. All I hear is a bunch of whining about something that you could possibly fix if you weren’t too busy seeking attention.

  69. Aw, this was a really nice post. Finding the time and actual effort to produce a top notch article… but what can I say… I procrastinate a whole lot and don’t manage to get nearly anything done.

  70. Can I just say what a relief to uncover someone that truly understands what they are talking about on the internet. You definitely know how to bring a problem to light and make it important. More and more people must check this out and understand this side of the story. I can’t believe you aren’t more popular since you definitely have the gift.

  71. I seriously love your website.. Excellent colors & theme. Did you make this site yourself? Please reply back as I’m trying to create my own website and would love to know where you got this from or what the theme is called. Thank you!

  72. Nice post. I used to be checking continuously this blog and I am
    impressed! Extremely helpful information specially the closing section 🙂 I maintain such info
    a lot. I used to be seeking this particular info for a long time.
    Thank you and good luck.

  73. Having read this I believed it was extremely informative. I appreciate you spending some time and energy to put this article together. I once again find myself spending a significant amount of time both reading and leaving comments. But so what, it was still worthwhile!

  74. The very next time I read a blog, Hopefully it doesn’t disappoint me as much as this particular one. After all, I know it was my choice to read through, however I truly believed you’d have something helpful to say. All I hear is a bunch of crying about something that you can fix if you were not too busy searching for attention.

  75. Heya i’m for the first time here. I found this board and I find It truly useful & it helped me out a lot. I hope to give something back and help others like you helped me.

  76. Good day! I just would like to give you a huge thumbs up for your great information you’ve got right here on this post. I will be coming back to your blog for more soon.

  77. Good post. I learn something new and challenging on sites I stumbleupon every day. It’s always helpful to read content from other authors and practice something from their sites.

  78. I’m impressed, I must say. Seldom do I come across a blog that’s both educative and engaging, and without a doubt, you’ve hit the nail on the head. The issue is an issue that too few men and women are speaking intelligently about. I am very happy that I came across this in my hunt for something relating to this.

  79. Hi, I do believe your website may be having internet browser compatibility issues. Whenever I take a look at your site in Safari, it looks fine however, if opening in IE, it has some overlapping issues. I just wanted to provide you with a quick heads up! Apart from that, excellent website.

  80. Greetings, I do think your web site might be having internet browser compatibility problems. Whenever I look at your website in Safari, it looks fine but when opening in IE, it’s got some overlapping issues. I merely wanted to provide you with a quick heads up! Aside from that, wonderful site!

  81. May I simply just say what a comfort to discover a person that genuinely understands what they are talking about online. You certainly understand how to bring a problem to light and make it important. A lot more people have to check this out and understand this side of the story. It’s surprising you’re not more popular given that you certainly have the gift.

  82. Right here is the right website for anyone who hopes to find out about this topic. You realize so much its almost hard to argue with you (not that I actually would want to…HaHa). You certainly put a new spin on a topic which has been written about for many years. Excellent stuff, just excellent.

  83. Greetings! Very useful advice within this article! It’s the little changes that make the largest changes. Many thanks for sharing!

  84. Spot on with this write-up, I honestly think this website needs a great deal more attention. I’ll probably be back again to read through more, thanks for the information!

  85. I really love your website.. Excellent colors & theme. Did you develop this amazing site yourself? Please reply back as I’m attempting to create my own personal site and want to learn where you got this from or what the theme is called. Many thanks!

  86. Oh my goodness! Amazing article dude! Thanks, However I am going through difficulties with your RSS. I don’t understand why I can’t subscribe to it. Is there anybody else getting the same RSS issues? Anyone that knows the answer will you kindly respond? Thanks!

  87. Hello there! This blog post couldn’t be written any better! Looking at this article reminds me of my previous roommate! He constantly kept talking about this. I’ll forward this information to him. Fairly certain he’ll have a good read. I appreciate you for sharing!

  88. I’m more than happy to find this site. I want to to thank you for your time for this wonderful read!! I definitely appreciated every part of it and i also have you saved as a favorite to check out new stuff in your blog.

  89. hello!,I love your writing so a lot! proportion we communicate more about your post on AOL? I need an expert in this space to resolve my problem. May be that is you! Taking a look ahead to peer you.

  90. You’re so awesome! I don’t suppose I’ve truly read through anything like this before. So wonderful to discover another person with some genuine thoughts on this subject matter. Seriously.. thanks for starting this up. This site is something that is required on the web, someone with a little originality.

  91. Hey there! I just want to give you a huge thumbs up for your excellent info you have got right here on this post. I will be returning to your site for more soon.

  92. An impressive share! I’ve just forwarded this onto a co-worker who had been conducting a little homework on this. And he actually ordered me dinner because I stumbled upon it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanks for spending the time to talk about this issue here on your website.

  93. An intriguing discussion is definitely worth comment. I do believe that you need to publish more on this topic, it might not be a taboo subject but typically people don’t talk about these issues. To the next! All the best!

  94. Howdy! This article could not be written any better! Reading through this article reminds me of my previous roommate! He constantly kept talking about this. I will send this article to him. Fairly certain he will have a very good read. I appreciate you for sharing!

  95. Hi there! I just wish to offer you a big thumbs up for the excellent info you have got right here on this post. I’ll be coming back to your web site for more soon.

  96. Having read this I believed it was really informative. I appreciate you spending some time and energy to put this short article together. I once again find myself spending a lot of time both reading and leaving comments. But so what, it was still worth it.

  97. Thanks for sharing excellent informations. Your web site is very cool. I’m impressed by the details that you’ve on this site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found just the info I already searched everywhere and simply couldn’t come across. What a great site.

  98. Aw, this was an exceptionally good post. Spending some time and actual effort to generate a great article… but what can I say… I procrastinate a whole lot and never seem to get nearly anything done.

  99. Google

    We prefer to honor several other web web pages on the net, even though they aren’t linked to us, by linking to them. Beneath are some webpages really worth checking out.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *