SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod rewrite and 404 problem

    Hi,

    I want to rewrite all pages which dont exist to /pages/$1.php
    So a request to "/about" will go to "/pages/about.php" but not redirected. This works fine with the code:

    Code:
    ErrorDocument 403 /errors/403.php
    ErrorDocument 404 /errors/404.php
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ pages/$1.php [QSA,L]
    BUT, when the page requested doesnt exist (eg if someone asks for "/aboot" and "/pages/aboot.php" doesnt exist), I want to show the normal 404 page. The code above gives a 500 error.

    Any solutions to this?

    Thanks for any help
    AlienDev
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  2. #2
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For anyone who finds the same problem as me, heres a solution I found (after alot of testing!):

    Code:
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ pages/$1.php [QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/?(.*)$ errors/404.php?request=$1 [QSA,L]
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.


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
  •