SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I make error pages using PHP template system?

    So I'm using a PHP template system meaning everything is run from template.php and it uses GET variable to pick the pages. So a url like:
    http://www.whatever.com?folder=fname&page=pname sends the content section of template.php the variables that are in pname.php in the fname folder.

    I'm using mod_rewrite to make my urls http://www.whatever.com/fname/pname instead and I want to know what is the best way to check if that page even exists so if the user types in fname/qname and qname.php doesn't exist it can send them to an error page?

    Any help would be great, thank you.

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    good ol' blighty
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can set a rewrite rule that passes everything through to a rewrite.php script, a script which checks for existence of certain items based on the incoming url like so.

    Code:
        #> EVERYTHING ELSE GETS INTERCEPTED BY A ALIAS SNIFFER
        RewriteRule  ^(.*)$                                     rewrite.php?href=$1                                         [NC,QSA,L]

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good idea, thanks. I ended up using the PHP file_exists function to test whether it was there before I loaded the content of the site into the template.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    good ol' blighty
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just remembered I should of also told you to escape certain folders by placing this rule infront of the rewrite posted as if you just use that rule everything goes through the php script which can impact performance.

    Code:
        #> SIMPLE FILES
         RewriteRule  ^(empty|privacy)\.html?$                    $1.html                                                    [QSA,L]
    
        #> PASSTHROUGH FOLDERS, obviously you change these to your required folders
        RewriteRule  ^(flash|images|storage|css|javascript)(.*)$         $1$2                                                                 [QSA,L]
    
        #> CGI BIN SCRIPTS
        RewriteRule  ^(.*)\.cgi$                                 $1.cgi                                                                [QSA,L]
    
        #> EVERYTHING ELSE GETS INTERCEPTED BY A ALIAS SNIFFER
        RewriteRule  ^(.*)$                                     rewrite.php?href=$1                                         [NC,QSA,L]

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is my current statement:

    Code:
    RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z_]+))?/?$ template.php?folder=$1&page=$3 [L]
    You are telling me to put those statements before this one? Also, what is empty|privacy, and when you listed all of the file types like javascript, css, etc... you want me to put the file extention like css, js instead, right?

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    good ol' blighty
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah no, only if you rewrite everything to the script.


Bookmarks

Posting Permissions

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