Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I redirect to 404 page in Code Igniter?

Posted on 2013-05-22
6
Medium Priority
?
4,479 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 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
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.

715 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