Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums Help & Support 404 Error pages not working i.c.w. Friendly URL's?
Hhawk
Posted on 03 Mar 2010, 09:25:39

Access: Member
Total Posts: 94
Joined: 2010-03-01

I am using the following .htaccess file:

Code:
ErrorDocument 404 /errors/404.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /nieuws2.php [L] 


As you can see, I use the Friendly URL's option. However if someone goes to a page which doesn't exist they would normally get my (custom) Error page. However since I added the Rewrite-stuff to the .htaccess file, it now automatically goes to the nieuws2.php page?

Any way to fix this?
#1987
Chris
Posted on 03 Mar 2010, 16:17:58

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

One way to tackle this would be a bit of custom code that checks the URL.

Just say for example this is one of your news links with friendly URLs enabled

Code:
http://yourdomain.com/news/1/0/title-of-page.html


The number 1 in the url is the ID of the news post. What you could do is check the URL and grab that number then check to see if that is a valid news post or not, if it is, show the news as normal, if not show your 404 page. This would also work if the user went to this page for example

Code:
http://yourdomain.com/ThisPageDoesntExist


Because there is no number after it, the script would know that there is no news article and again show the 404 page.

To do this try this code

Code:
<?php
require_once 'news/db.php';
require_once 
'news/config.php';
// these need to be included

$exists_id = $_SESSION['url']['2'];
$news_exists = DataAccess::fetch("SELECT id FROM $newstable WHERE id = ?", $exists_id);
if(
count($news_exists) > 0){
    
// the news post exists so put your normal news include code here
    
include 'news/index.php';
}else{
    
// the news post doesn't exist so include your 404 page
    
include '404.php';
}
?>
#1996
Last edited by Chris at 2010-03-03 16:18:12 Reason:
Hhawk
Posted on 03 Mar 2010, 17:31:11

Access: Member
Total Posts: 94
Joined: 2010-03-01

Okay thanks, I will give it a go. :)
#2004
Hhawk
Posted on 04 Mar 2010, 08:20:10

Access: Member
Total Posts: 94
Joined: 2010-03-01

Quote:
Doesn't seem to be true. If I type: http://www.deelektrischeauto.nl/ThisPageDoesntExist (or anything else) it still shows the news page?

This is what it's supposed to do. Because all non-existent pages get redirected to the news page, the above code turns the news page into a make shift 404 page. Basically it checks the url to see if it's a friendly URL made by the news system, if not then instead of including the news system, it includes the 404 page.
#2012
Last edited by Chris at 2010-03-04 23:07:58 Reason:
Network-13.com © 2013