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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Location
    Manchester
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing file extensions

    Just taken on a site that has a rewrite rule in place to remove & redirect .php extensions. i.e /about.php will become /about.
    However, there are other rules in place and I have just noticed that if the url parameter doesn't match the rewrite condition a 501 Internal Server Error is thrown as opposed to a 404.
    It is definately the rule that removes the .php that is causing the issue as commenting it out solves the issue, however this rule must be left in place.

    Code:
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^archive/([A-Z]{1})$ archive.php?letter=$1 [L]
    RewriteRule ^page/([0-9]+)$ page.php?id=$1 [L]
    
    # Remove .php extension
    RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
    RewriteRule (.*)\.php$ $1 [R=301]
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.php [L]
    
    ErrorDocument 404 /missing
    ErrorDocument 403 http://www.disney.com
    Ok, so if the URL is http://www.foobar.com/page/1 then it works fine. Same for removing the .php extension http://www.foobar.com/about.php will become http://www.foobar.com/about. However if I try to use an invalid URL (on an existing mod rewrite rule) to test a 404 i.e http://www.foobar.com/archive/123 then I will get a 500 Internal server error.

    Any ideas? Mod Rewrite not really my strongest area for debugging.

  2. #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by neil.johnson View Post
    Just taken on a site that has a rewrite rule in place to remove & redirect .php extensions. i.e /about.php will become /about.
    However, there are other rules in place and I have just noticed that if the url parameter doesn't match the rewrite condition a 501 Internal Server Error is thrown as opposed to a 404.
    It is definately the rule that removes the .php that is causing the issue as commenting it out solves the issue, however this rule must be left in place.

    Code:
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^archive/([A-Z]{1})$ archive.php?letter=$1 [L]
    RewriteRule ^page/([0-9]+)$ page.php?id=$1 [L]
    
    # Remove .php extension
    RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
    RewriteRule (.*)\.php$ $1 [R=301]
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.php [L]
    
    ErrorDocument 404 /missing
    ErrorDocument 403 http://www.disney.com
    Ok, so if the URL is http://www.foobar.com/page/1 then it works fine. Same for removing the .php extension http://www.foobar.com/about.php will become http://www.foobar.com/about. However if I try to use an invalid URL (on an existing mod rewrite rule) to test a 404 i.e http://www.foobar.com/archive/123 then I will get a 500 Internal server error.

    Any ideas? Mod Rewrite not really my strongest area for debugging.
    you can enable logging for rewrite, for debugging purpouse only:

    http://httpd.apache.org/docs/2.2/logs.html#other

    usualy you can find in the server error logs what is wrong, what cause the 500 message, did you look inside? typos in .htacces is one cause.

    best regards


 

Posting Permissions

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