Jump to content
Larry Ullman's Book Forums

andrey

Members
  • Posts

    10
  • Joined

  • Last visited

Posts posted by andrey

  1. Okay, to start, if the URL for the site is http://artsite1, then you don't want to use RewriteBase /artsite1/ because the site is effectively in the root. 

     

    Similarly, your ErrorDocument ends up being incorrect as it points to http://artsite1/artsite1/index.php

    Thank you ! Fixed bug. But there is no redirect. Now I'm studying the settings of my OpenServer. Maybe the reason is there.

  2. My file .htaccess

    # Script 2.7 - .htaccess
    <IfModule mod_rewrite.c>
    
    # Turn on the engine:
    RewriteEngine on
    
    # Set the base to this directory:
    RewriteBase /artsite1/
    
    # Redirect certain paths to index.php:
    RewriteRule ^(about|contact|this|that|search|error404)/?$ index.php?p=$1
    
    ErrorDocument 404 /artsite1/index.php?p=error404
    
    </IfModule>
    

    My URL: http: //artsite1/index.php. And erroneous requests for an existing file, For example http: //artsite1/abrakadabra.html. Yes, redirection proceeds.

  3.  

    Hello everyone!

    I try to make a error page based on Larry code. but encountered a problem. There was a Problem with a redirect of this type:

     

    $url = BASE_URL . 'index.php?p=error404';
        header("Location: $url");
        exit;
    
    All your options exhausted.

    Please suggest an algorithm of actions. How can I cope with it.

     

    htaccess

    # Script 2.7 - .htaccess
    <IfModule mod_rewrite.c>
    
    # Turn on the engine:
    RewriteEngine on
    
    # Set the base to this directory:
    RewriteBase /ch02/
    
    # Redirect certain paths to index.php:
    RewriteRule ^(about|contact|this|that|search|error404)/?$ index.php?p=$1
    
    ErrorDocument 404 http://ch02/index.php?p=error404
    
    </IfModule>
    

    index.php

    <?php # Script 2.4 - index.php
    
    /* 
     *  This is the main page.
     *  This page includes the configuration file, 
     *  the templates, and any content-specific modules.
     */
    
    // Require the configuration file before any PHP code:
    require('config.inc.php');
    
    // Validate what page to show:
    if (isset($_GET['p'])) {
        $p = $_GET['p'];
    } elseif (isset($_POST['p'])) { // Forms
        $p = $_POST['p'];
    } else {
        $p = NULL;
    }
    
    // Determine what page to display:
    switch ($p) {
    
        case 'about':
            $page = 'about.inc.php';
            $page_title = 'About This Site';
            break;
        
        case 'contact':
            $page = 'contact.inc.php';
            $page_title = 'Contact Us';
            break;
        
        case 'search':
            $page = 'search.inc.php';
            $page_title = 'Search Results';
            break;
    		
    		case 'error404':
            $page = 'error404.inc.php';
            $page_title = 'Error!';
            break;
        
        // Default is to include the main page.
        default:
            $page = 'main.inc.php';
            $page_title = 'Site Home Page';
            break;
            
    } // End of main switch.
    
    // Make sure the file exists:
    if (!file_exists('./modules/' . $page)) {
        $page = 'main.inc.php';
        $page_title = 'Site Home Page';
    }
    
    // Include the header file:
    include('header.html');
    
    // Include the content-specific module:
    // $page is determined from the above switch.
    include('./modules/' . $page);
    
    // Include the footer file to complete the template:
    include('footer.html');
    ?>
    

     

     

     

  4. Hello everyone!

    I try to make a error page based on Larry code. but encountered a problem. There was a Problem with a redirect of this type:

     


    $url = BASE_URL . 'index.php?p=error404';
        header("Location: $url");
        exit;
    
    All your options exhausted.

    Please suggest an algorithm of actions. How can I cope with it.

     

    htaccess

    # Script 2.7 - .htaccess
    <IfModule mod_rewrite.c>
    
    # Turn on the engine:
    RewriteEngine on
    
    # Set the base to this directory:
    RewriteBase /ch02/
    
    # Redirect certain paths to index.php:
    RewriteRule ^(about|contact|this|that|search|error404)/?$ index.php?p=$1
    
    </IfModule>
    

    index.php

    <?php # Script 2.4 - index.php
    
    /* 
     *  This is the main page.
     *  This page includes the configuration file, 
     *  the templates, and any content-specific modules.
     */
    
    // Require the configuration file before any PHP code:
    require('config.inc.php');
    
    // Validate what page to show:
    if (isset($_GET['p'])) {
        $p = $_GET['p'];
    } elseif (isset($_POST['p'])) { // Forms
        $p = $_POST['p'];
    } else {
        $p = NULL;
    }
    
    // Determine what page to display:
    switch ($p) {
    
        case 'about':
            $page = 'about.inc.php';
            $page_title = 'About This Site';
            break;
        
        case 'contact':
            $page = 'contact.inc.php';
            $page_title = 'Contact Us';
            break;
        
        case 'search':
            $page = 'search.inc.php';
            $page_title = 'Search Results';
            break;
    		
    		case 'error404':
            $page = 'error404.inc.php';
            $page_title = 'Error!';
            break;
        
        // Default is to include the main page.
        default:
            $page = 'main.inc.php';
            $page_title = 'Site Home Page';
            break;
            
    } // End of main switch.
    
    // Make sure the file exists:
    if (!file_exists('./modules/' . $page)) {
        $page = 'main.inc.php';
        $page_title = 'Site Home Page';
    }
    
    // Include the header file:
    include('header.html');
    
    // Include the content-specific module:
    // $page is determined from the above switch.
    include('./modules/' . $page);
    
    // Include the footer file to complete the template:
    include('footer.html');
    ?>
    
×
×
  • Create New...