krike Posted December 11, 2009 Share Posted December 11, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/ Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975544 Share on other sites More sharing options...
krike Posted December 11, 2009 Author Share Posted December 11, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975583 Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975598 Share on other sites More sharing options...
krike Posted December 11, 2009 Author Share Posted December 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975615 Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 Just before the rule in question, try putting... RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975618 Share on other sites More sharing options...
krike Posted December 11, 2009 Author Share Posted December 11, 2009 still getting the server error. maybe it's because I'm working localy..? Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975638 Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975643 Share on other sites More sharing options...
krike Posted December 11, 2009 Author Share Posted December 11, 2009 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 thanks for your quick answers and help Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975646 Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 Try checking out this, it should make testing a lot easier as your localhost will then be the same as your live server. Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-975653 Share on other sites More sharing options...
krike Posted January 22, 2010 Author Share Posted January 22, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/184790-internal-server-error-when-browsing-pages-that-do-not-exist/#findComment-999934 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.