Solved

How can I redirect to 404 page in Code Igniter?

Posted on 2013-05-22
6
3,817 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 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

23 Experts available now in Live!

Get 1:1 Help Now