Jump to content

internal server error when browsing pages that do not exist


Recommended Posts

The following code works perfectly but when I browse a page that doesn't exist I get an internal server error.

 

RewriteEngine on

#RewriteCond %{REMOTE_HOST} !^81\.165\.9\.219
#RewriteRule .* http://www.iv-designs.org/maintenance/maintenance.html [R=302,L]

RewriteBase /cmstut/

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^ - [L]

#tutorial rewrites
RewriteRule ^index/page/([0-9]+)$ /cmstut/index.php?page=$1 [QSA,L]
RewriteRule ^tutorial/([0-9]+)$ /cmstut/view_tutorial.php?tutorial_id=$1 [QSA,L]
RewriteRule ^submitted/([0-9]+)$ /cmstut/submitted_tutorial.php?tutorial_id=$1 [QSA,L]
RewriteRule ^add_favorite/([0-9]+)$ /cmstut/add_favorites.php?tutorial_id=$1 [QSA,L]
RewriteRule ^favorites/(.*)$ /cmstut/favorites.php?username=$1 [QSA,L]
RewriteRule ^user/(.*)$ /cmstut/profile.php?username=$1 [QSA,L]
RewriteRule ^edituser/(.*)$ /cmstut/edit_profile.php?username=$1 [QSA,L]
RewriteRule ^search/category/([0-9]+)$ /cmstut/search.php?category_id=$1 [QSA,L]
RewriteRule ^search/category/([^/]+)/page/([0-9]+)$ search.php?category_id=$1&page=$2 [QSA,L]
RewriteRule ^search/tags/([^/]+)$ /cmstut/search.php?tags=$1 [QSA,L]
RewriteRule ^search/tags/([^/]+)/page/([^/]+)$ /cmstut/search.php?tags=$1&page=$2 [QSA,L]
RewriteRule ^search/(.*)$ search.php?search=$1 [QSA,L]
RewriteRule ^search/([^/]+)/page/(.*)$ search.php?search=$1&page=$2 [QSA,L]

RewriteRule ^feature_tutorial/extend/([0-9]+)$ /cmstut/feature_tutorial.php?action=extend&tut=$1 [QSA,L]

#shop rewrites
RewriteRule ^shop/item/([^/]+)$ /cmstut/shop/item.php?item=$1 [QSA,L]
RewriteRule ^shop/item/([^/]+)/page/([0-9]+)$ /cmstut/shop/item.php?item=$1&page=$2 [QSA,L]
RewriteRule ^shop/item_preview/(.*)$ /cmstut/shop/item_preview.php?itemid=$1 [QSA,L]
RewriteRule ^shop/downloads/([^/]+)$ /cmstut/shop/downloads.php?download=$1 [QSA,L]
RewriteRule ^shop/downloads/page/([0-9]+)$ /cmstut/shop/downloads.php?page=$1 [QSA,L]
RewriteRule ^shop/cat/([^/]+)$ /cmstut/shop/cat.php?cat=$1 [QSA,L]
RewriteRule ^shop/cat/([^/]+)/page/([0-9]+)$ /cmstut/shop/cat.php?cat=$1&page=$2 [QSA,L]


#rewrite all other pages
RewriteRule ^(.+[^/])$ /cmstut/$1.php [QSA,L]
#remove last trailing slash
RewriteRule (.+)/$ /cmstut/$1 [L,R=301]
RewriteRule (.+)/$ /cmstut/shop/$1 [L,R=301]

I'm not sure I understand your RewriteCond's, I thought -d meant the file exists whereas it appears you actually wish to redirect files that don't exist !-d (ie http://www.domain.com/tutorial/12 to http://www.domain.com/cmstut/view_tutorial.php?tutorial_id=$i) Therefore all the URLs you are typing in "don't exist". Can you give an example of a URL that causes the internal error?

what do you mean I redirect pages that does not exist? where do you see !-d?

 

I only get an internal server error when I type a url of a page that DOES NOT exist, so they don't get the 404 not found but 505 internal server error. all the rest is working fine. and the rewritebase /cmstut/ is just to make it work localy on my wamp server.

 

I just tried to delete each line to see what is causing the problem and it's the line that should remove the php extenion of all pages.

 

#rewrite all other pages
RewriteRule ^(.+[^/])$ /cmstut/$1.php [QSA,L]

I don't see !-d which is my whole point. Take the following RewriteRule and lets assume your domain is http://www.example.com...

 

RewriteRule ^tutorial/([0-9]+)$ /cmstut/view_tutorial.php?tutorial_id=$1

 

The whole objective of that RewriteRule is that if the server receives a request for the page http://www.example.com/tutorial/10 it will show the user the page http://www.example.com/cmstut/view_tutorial.php?tutorial_id=$1. Since http://www.example.com/tutorial/10 doesn't actually exist on your server, the client has requested a file that does not exist.

 

I only get an internal server error when I type a url of a page that DOES NOT exist, so they don't get the 404 not found but 505 internal server error.

None of those URLs actually exist, that is my point. You DO NOT have a file/directory on the server called http://www.example.com/tutorial/10.

 

I just tried to delete each line to see what is causing the problem and it's the line that should remove the php extenion of all pages.

 

#rewrite all other pages
RewriteRule ^(.+[^/])$ /cmstut/$1.php [QSA,L]

That line doesn't remove the extension, your objective may well be that the visitor doesn't see the extension, that means your RewriteRule nees to add the extension. I'll say again, what URL are you typing in that is producing the error.

The whole objective of that RewriteRule is that if the server receives a request for the page http://www.example.com/tutorial/10 it will show the user the page http://www.example.com/cmstut/view_tutorial.php?tutorial_id=$1. Since http://www.example.com/tutorial/10 doesn't actually exist on your server, the client has requested a file that does not exist.

 

I'm working on localhost, in my www folder I have a folder cmstut, all my files are in there. If I don't add the /cmstut it will redirect me to http://localhost/shop/index if I browse for http://localhost/cmstut/shop/index

 

But that's not the problem, I have a php file and would browse it normally like http://localhost/cmstut/deposit.php, by rewritting it I can browse the same file as http://localhost/cmstut/deposit

 

now when I browse a file that does not exist by using the normal link http://localhost/cmstut/randomfile.php or using the rewrite rule http://localhost/cmstut/randomfile that will give me a 505 internal server error

I think you'll find if you comment out all the other rules that one will work (given those RewriteCond), it works for me. Which means it's probably a conflict between two different rules. Try amending [QSA,L] to [R] and see what happens to the address.

I've cut all the lines except the one you say you tested, it still didn't work so I removed both /cmstut then it gave me the 404 not found rather then 505. I guess that gives a problem working on localhost, but when I go live the /cmstut will be removed anyway to match the domain, so I think it will be fixed then. if not I'll reply again :D

 

thanks for your quick answers and help :)

  • 1 month later...

I finally finished the website and uploaded the files but I'm still getting the internal server error. if you go to http://cmstutorials.org/testing.php (which doesn't exist) it will give and internal server error.

 

when I remove the line to rewrite the other pages it works fine so I guess there is something wrong with that line.

RewriteRule ^(.+[^/])$ $1.php [QSA,L]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.