Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I redirect to 404 page in Code Igniter?

Posted on 2013-05-22
6
Medium Priority
?
4,636 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 2000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

885 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