BulleTTime Posted December 20, 2012 Share Posted December 20, 2012 Hi, I have the following htaccess file, because i would like to turn http://www.example.com/pageName into http://www.example.com/index.php?page=pageName. This part works. however i have two things i would like to fix. 1) In my php code i check if the page excists in the database, otherwise i make a header to 404 using header("HTTP/1.0 404 Not Found"); . It seems that the header not works, and i quess because of the RewriteRule. Does anyone knows how i would fix this? can i fix this inside the htaccess file? 2) secondly i notices that when i go to http://www.example.com/pageName/ (with a slash at the end) the page cant be found. Options +FollowSymLinks # IndexIgnore */* # Turn on the RewriteEngine RewriteEngine On # Rules RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ([^\s]+)([a-z-\s]*) index.php?page=$1&display=$2 ErrorDocument 404 /error.php ErrorDocument 400 /error.php ErrorDocument 401 /error.php ErrorDocument 403 /error.php ErrorDocument 405 /error.php ErrorDocument 406 /error.php ErrorDocument 409 /error.php ErrorDocument 413 /error.php ErrorDocument 414 /error.php ErrorDocument 500 /error.php ErrorDocument 501 /error.php Any help would be great! Quote Link to comment https://forums.phpfreaks.com/topic/272210-rewriterule-404-error-page/ Share on other sites More sharing options...
Christian F. Posted December 20, 2012 Share Posted December 20, 2012 My guess is that the header works, but you're actually showing the user the error page. Simply sending the 400 header to the client isn't enough, you also have to either redirect or include the error page as well. Otherwise whatever the default output is it'll be shown to the client. After all, PHP doesn't know what sending any particular headers means, unless you tell it. Quote Link to comment https://forums.phpfreaks.com/topic/272210-rewriterule-404-error-page/#findComment-1400567 Share on other sites More sharing options...
BulleTTime Posted December 20, 2012 Author Share Posted December 20, 2012 Thanks, but. how can i check if the header already works? Because google keeps crawling the old url's from the old site. Also any idea how to fix the slash (2nd question)? Quote Link to comment https://forums.phpfreaks.com/topic/272210-rewriterule-404-error-page/#findComment-1400583 Share on other sites More sharing options...
Christian F. Posted December 20, 2012 Share Posted December 20, 2012 The easiest way to check and see if it works, is by simply requesting the page and monitor the HTTP response. Most modern browsers (the exception being IE, and possibly Safari) have developer tools which allow you to not only inspect the DOM, but also the HTTP requests (and responses). There are also other tools that can do this, with cURL or wget being two such tools. In short: Anything that displays the headers from the server will do. As for the second question, try this: RewriteRule ([^\s]+)([a-z-\s]*)/? index.php?page=$1&display=$2 Quote Link to comment https://forums.phpfreaks.com/topic/272210-rewriterule-404-error-page/#findComment-1400585 Share on other sites More sharing options...
BulleTTime Posted December 20, 2012 Author Share Posted December 20, 2012 Okay thanks. that works. I tried the rewriteRule code but still getting 404 then (ending with a slash). Also, is it able to support upper and lowercases? when i try "pagename" instead of "pageName" i notice that some parts of my site missing... Quote Link to comment https://forums.phpfreaks.com/topic/272210-rewriterule-404-error-page/#findComment-1400591 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.