PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Nov 16, 2018 8:28 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Removing file extensions
PostPosted: Fri Mar 25, 2011 5:07 am 
Offline
Forum Newbie

Joined: Fri May 09, 2008 6:01 am
Posts: 4
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.


Top
 Profile  
 
PostPosted: Fri Mar 25, 2011 7:04 am 
Offline
DevNet Resident
User avatar

Joined: Thu May 14, 2009 3:00 pm
Posts: 1011
Location: HellCity, Bulgaria
You can achieve the effect of removing file extension by enabling MultiViews


Top
 Profile  
 
PostPosted: Fri Mar 25, 2011 7:12 am 
Offline
Forum Newbie

Joined: Fri May 09, 2008 6:01 am
Posts: 4
No, used that before and it screws up other rewrite rules i.e if I had a page about.php it will work as /about,
however if I use
Code:
^about/([0-9]) foobar.php?x=$1 [L]

i.e in a rewrite rule it will think I want about.php instead of foobar.php


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group