Solved

How can I redirect to 404 page in Code Igniter?

Posted on 2013-05-22
6
4,323 Views
Last Modified: 2013-05-31
I have CI website with Mysql connected. How can I redirect to 404 page if someone type in the URl editing? For ex: http://andhimazhai.com is the website, if someone type like this, http://andhimazhai.com/search/  it should redirect to 404 page but at preset it reports error.
0
Comment
Question by:Loganathan Natarajan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39186946
Add to Your controller that if view page  is not exist then redirect to 404 Like:
 
if ( ! file_exists('application/search/'.$page.'.php'))
	{
		show_404();
	}

Open in new window

0
 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 39186960
How can I check for this dynamic parameter pages?

Right URL
http://andhimazhai.com/news/view/tgte-22-05-2013-.html

Modified wrong URL,

http://andhimazhai.com/news/view/tgte-22-05-2343242013-.html
0
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 500 total points
ID: 39186988
It's seem in your CI  there is controller folder which have news.php controller and have method (function) view, Now in your model where you fetch news using newsid or some parameter/querystring you need to check if the news is exist or not Like:

if (empty($data['news_item']))
	{
		show_404();
	}

Open in new window


Again which version of CI you are using? It's better to refer you CI tutorial
http://ellislab.com/codeigniter/user-guide/tutorial/
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 39187011
Is there a common way to handle these ?
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39187070
Yes if you can check the query string passed for news
0
 
LVL 36

Author Closing Comment

by:Loganathan Natarajan
ID: 39212392
Thank you
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question