Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    J&J
    J&J is offline
    New Coder
    Join Date
    Sep 2003
    Location
    your temp folder
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PHP template won't redirect bogus pages to error 404

    A site I'm working on uses a php template called LAYOUT.php to call the html pages into it via the include("$page.html") statement.

    All links are written like so:
    Code:
    <a href="LAYOUT.php?page=whatsnew">What's New</a>
    Now, the error pages are specified in an .htacess file, for example:
    Code:
    ErrorDocument 404 http://www.domain.com/LAYOUT.php?page=404

    Are you with me so far? My question now is, when linking to nonexistent (soon-to-be-made) pages, why does it display the blank template, instead of showing the 404 error page? Try this link for example.

    Is there a way to make this work, even if it means ditching htaccess and using PHP instead?

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What kind of checking is in place to determine whether the page is blank or not? If you posted some of the code it might help to see where the script is going wrong.

  • #3
    J&J
    J&J is offline
    New Coder
    Join Date
    Sep 2003
    Location
    your temp folder
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the coding for LAYOUT.php. I've colored all PHP in blue for you:
    Code:
    <?php if ($page == "") {$page="home";} ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<base href="http://sims2.jandjwebservices.com/" target="_top" />
    
    			<title>Simply Irresistible!</title>
    		
    	<link rel="shortcut icon" type="image/x-icon" href="http://sims2.jandjwebservices.com/favicon.ico" />
    	<link rel="stylesheet" type="text/css" href="http://sims2.jandjwebservices.com/styles.css" />
      <script type="text/javascript" src="http://sims2.jandjwebservices.com/headers.js"></script>
    </head>
    
    <body id="simply-irresistible">
    
    <h1 class="replace" id="pageHdr">SIMply Irresistible! A FREE Sims 2 Fansite<span></span></h1>
    
      <div id="container">
      	<div id="leftCol">
    		
      		<!-- START CONTENT //-->
            <div id="leftHdr"></div>
            <div id="leftBody">
            	<?php @ include("$page.html"); ?>
            </div>
            <div id="leftEnd"></div>
    			<!-- END CONTENT //-->
    			
    			<div id="footHdr"></div>
      		<div id="footBody">
    				<p><em>SIMply Irresistible!</em> <b>&copy;2005, All Rights Reserved Worldwide.<br />
            Site designed &amp; maintained by <a href="http://www.jandjwebservices.com" target="_blank">J&amp;J Web Services</a>.</b><br />
            <applet code='counter' codebase='http://jandjwebservices.com/v-web/counter'
                 width='94' height='20' alt="Counter">
                <param name='counter' value='sims2'>
                <param name='style' value='32'>
                <param name='minsize' value='6'>
                <param name='bgcolor' value='#ffffff'>
                <param name='twoclicks' value='http://simply-irresistible.org'>
            </applet>
            </p>
    
            <p><b>COPYRIGHT NOTICE &amp; DISCLAIMER</b><br />
            <small>This website in its entirety is copyrighted to "SIMply Irresistible!" unless otherwise noted.  Viewing of this website, downloading any files, and accessing its web pages signifies that you have read, understood, and agree to our <a href="LAYOUT.php?page=notice" target="_blank">copyright notice &amp; disclaimer</a>. Thank you for your compliance!</small></p>
            
            <p>This site is not endorsed by or affiliated with Maxis, Electronic Arts, or its licensors.<br />
            Trademarks are the property of their respective owners.<br />
            Game content and materials copyright Electronic Arts Inc. and its licensors.  All Rights Reserved.</p>
      		</div>
    			<div id="footEnd"></div>
      
      	</div><!-- end leftColumn //-->
    
    	
      	<div id="rightCol">
      		<!-- START MENU //-->
    				<?php @ include("MENU.php"); ?>
    			<!-- END MENU //-->
      	</div><!-- end rightColumn //-->
    
    	</div><!-- end container //-->
    
    </body>
    </html>
    Go to the site: click here

    Then click on "What's New " at the bottom-righthand corner of the page. It shows an empty shell (blank template), instead of 404 page error.
    ~ J&J ~
    "Sometimes I feel like I'm rearranging deck chairs on the Titanic."


    Work | Family | Community

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, well there's no checking in that code to determine if $page is actually a page that exists or not. Try adding something like this to the top of the script:
    PHP Code:
    <?php if ($page == "") {$page="home";}
    if(!
    file_exists($page '.html')) {
        
    header('Location: http://www.domain.com/LAYOUT.php?page=404');
    }
    ?>

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yep, the .htaccess files will search for errordocuments on 404 NOT FOUND. Key word, not found. The page is there, so it won't work for the .htaccess file. I'm not an apache .htaccess file kind of guy so it may be possible to do, but probably not worth your while.
    Delinear's method is the best bet when it comes to a php solution for sure. Nice and simple, page not there, 404.
    You keep beating me to all of these posts today

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu
    You keep beating me to all of these posts today
    Aww shucks, I try and leave all the tough ones for you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •