SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2007
    Location
    West Coast
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Eror 404 not working with directories

    My code is not working for old pages that have trailing slashes which have been deleted

    Actually the page is now site.com/page1 from site.com/page1/ if it has a trailing slash it gives a 500 internal server error/, not the 404 which happens on regular page that have no trailing slash.

    Code:
    ErrorDocument 404 http://www.domain.com/404
    
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^domain.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,656
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    lukkas,

    Some overlap with your other thread ... but try using

    Code:
    ErrorDocument 404 /404.php 
    # internal absolute URI is required
    
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^domain\.com [NC] 
    # escape the dot character and use No Case on domain names (which are NOT case sensitive)
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
    # (.*) duplicates the {REQUEST_URI} variable but if you insist ...
    
    RewriteBase / # ARGH! Forcing everything through the DocumentRoot when sitting in the DocumentRoot is not good technique.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}\.php -f # You forgot to escape the dot
    RewriteRule .? %{REQUEST_URI}.php [L] # URIs are case sensitive so do NOT use No Case flag in a RewriteRule!
    Explanations in the other thread.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •