Solved

How can I redirect to 404 page in Code Igniter?

Posted on 2013-05-22
6
3,736 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now