yamikowebs Posted August 20, 2012 Share Posted August 20, 2012 I have been working on my own framework and learning more advanced PHP than what I was able to learn in college. I use .htacess to redirect all page request to my bootstrap file. The bootstrap file will then parse Request URI and run the necessary controllers etc. If the controller does not exist it runs a 404 controller that send a 404 header. After the controller and vies are made they are passed to a template and then echoed to the page. If I request a faulty page I get the 404 error just fine. However If i request a valid page and the page request css files images that do not exist they will not generate the proper 404 header. They return the same header as the original page requested. Options +FollowSymLinks IndexIgnore */* # Turn on the RewriteEngine RewriteEngine On # Redirect to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php //the tid bit that loads the controller //locate $file = 'Lume/' . self::$AppPath . 'Controller/' . self::$ControllerName; if(!file_exists($file . '.php')){ header('HTTP/1.0 404 Not Found'); $file='Lume/' . self::$AppPath . 'Controller/_404.php'; } //create $controller = str_replace('/', '\\', '/' . $file); if(!is_subclass_of($controller, '\Lume\Abstracts\Controller')) throw new \Exception('Route::Main The controller must extend from Lume\Abstracts\Controller'); self::$Controller =& new $controller(); //run self::$Controller->Main(); Quote Link to comment https://forums.phpfreaks.com/topic/267346-cant-generate-404-headers-on-pages-other-than-the-requested-page/ Share on other sites More sharing options...
yamikowebs Posted August 20, 2012 Author Share Posted August 20, 2012 The above code was tested on my local server. I moved it to my live server on a test domain and got more information. On my live server I was getting an error about output already being sent from another file...This is confusing because the file that is starting the so called output is an abstract class and the line the error is for is an abstract function... namespace Lume\Abstracts; abstract class Chain{ abstract protected static function GetSelf();//this is the line that is starting output abstract protected static function SetSelf(); } Quote Link to comment https://forums.phpfreaks.com/topic/267346-cant-generate-404-headers-on-pages-other-than-the-requested-page/#findComment-1370877 Share on other sites More sharing options...
requinix Posted August 20, 2012 Share Posted August 20, 2012 If you're not getting a 404 then presumably the framework sent something back. What did it send? Quote Link to comment https://forums.phpfreaks.com/topic/267346-cant-generate-404-headers-on-pages-other-than-the-requested-page/#findComment-1370913 Share on other sites More sharing options...
yamikowebs Posted August 21, 2012 Author Share Posted August 21, 2012 It is sending back the same result as the page request. I.E If I request a non existing page I get a 404. If I request a valid page Foo.php that has invalid links to css files etc. Those invalid files will have the same response as the request for Foo.php Quote Link to comment https://forums.phpfreaks.com/topic/267346-cant-generate-404-headers-on-pages-other-than-the-requested-page/#findComment-1371145 Share on other sites More sharing options...
ManiacDan Posted August 21, 2012 Share Posted August 21, 2012 Those invalid files will have the same response as the request for Foo.phpSo instead of base.css I get Foo.php again? That doesn't make much sense. Or do you mean you're getting a 200OK with no content? Quote Link to comment https://forums.phpfreaks.com/topic/267346-cant-generate-404-headers-on-pages-other-than-the-requested-page/#findComment-1371172 Share on other sites More sharing options...
yamikowebs Posted August 21, 2012 Author Share Posted August 21, 2012 It returns 200 ok. In firebug on the html part of the response it has the same output as my main page though =/ This is my first time playing with the ideas of routing with htaccess and MVC so I might have redo the whole thing and start with a more abstract use of it to get the idea down. Would you know of any good tutorials that go through setting 404s for invalid controllers. My URL format is site.com/controller/method/params/moreparams Quote Link to comment https://forums.phpfreaks.com/topic/267346-cant-generate-404-headers-on-pages-other-than-the-requested-page/#findComment-1371243 Share on other sites More sharing options...
yamikowebs Posted August 22, 2012 Author Share Posted August 22, 2012 Those invalid files will have the same response as the request for Foo.phpSo instead of base.css I get Foo.php again? That doesn't make much sense. Or do you mean you're getting a 200OK with no content? So I started working on a simpler attempt to get the idea down and almost got it with RewriteRule !.(js|ico|txt|gif|jpg|png|css)$ index.php [L,QSA] I want everything to redirect to index.php except for actual files, directories or request for something in the Resoureces directory. That way I can pass image names with the extensions in the url if I wanted and generate proper 404 for requesting images, CSS files etc since they would be stored in the Resources directory. I cant figure out how to get it to only prevent routing on Resources/*. I thought the code below would do it but something is wrong it is redirecting Resources/invalidfile to index.php ReqriteRule !Resources/*$ index.php [L,QSA] Quote Link to comment https://forums.phpfreaks.com/topic/267346-cant-generate-404-headers-on-pages-other-than-the-requested-page/#findComment-1371300 Share on other sites More sharing options...
yamikowebs Posted August 22, 2012 Author Share Posted August 22, 2012 RewriteRule !^(Resources(/.*)?)$ index.php [L,QSA] did the trick Quote Link to comment https://forums.phpfreaks.com/topic/267346-cant-generate-404-headers-on-pages-other-than-the-requested-page/#findComment-1371305 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.