nx2wes Posted July 22, 2011 Share Posted July 22, 2011 I'm trying to work out a kink with Internet Explorer. My website is MySQL driven. In the past, I created this system so that I could have "friendly" URLS. For example, I want people to be able to type in /news/somestory/ rather than /news/?id=234. To accomplish this, I set up a MySQL table with two columns: ID, URL For example: ID URL 1 somestory 2 anotherstory 3 whatever Since the folder /news/somestory/ doesn't actually exist, if someone types it in, they'll get a 404 error. So, I configured the .htaccess to redirect 404 errors to a PHP handler: ErrorDocument 404 /error.php Finally, /error.php checks to see if the URL exists in the MySQL database. If so, it echoes an IFRAME containing the true url (e.g., /news/?id=1), which keeps the friendly URL (/news/some_story/) in the address bar. If the URL does not exist in the database, it redirect to the homepage (like I want it to). $page = explode("?",$_SERVER['REQUEST_URI']); $url = $page[0]; // URL is anything before ? $url = preg_replace('/^\/news\//','',$url); // Strip /news/ from beginning $url = preg_replace('/\/$/','',$url); // Strip slashes $parameters = $page[1]; // Parameters are anything after ? $rs = @mysql_query("select `id` from `pages` where `url`='$url' limit 1"); // Look up the ID number from the database if(!(@mysql_num_rows($rs)==1){ // If there is no ID number in the database header("Location: /"); // Go to homepage die(); } $id = @mysql_fetch_array($rs); // Else, grab the ID number from the database $id = $id['id']; // Echo a full-screen iFrame with the content in it. echo "<iframe style='width:100%;height:100%;' src='/news/?id=$id&$parameters'></iframe>"; I've been using this system for a while, now. When developing a new website recently, I used a similar script. It works beautifully in Firefox. However, I checked this in Internet Explorer 9 and found that IE9 is now showing a built-in 404 page. Curiously, IE will make it to the header("Location: /") redirect. So, if someone types /news/a_url_that_doesnt_exist_in_database/, they will be correctly redirected to the homepage. However, if legitimate content exists and I attempt to echo the <iframe>, I get the 404 message. This is apparently because IE9 has a setting (checked by default) "Show friendly HTTP error messages." So, as soon as IE gets the 404 header, it stops and shows its default error page. With the "friendly HTTP errors" option unchecked, the script works in IE. I obviously can't uncheck this box for all of my users, so is there a way to make the website work properly? After some research, I tried inserting a header at the top of /error.php: header("HTTP/1.1 200 OK"); This didn't work. IE still displayed the 404 error message. Can anyone help? Are there additional PHP headers that will help? Is there a way to rewrite the .htaccess that will help? Is there a better system than my 404-based system for creating friendly URLs? I appreciate your help! Quote Link to comment https://forums.phpfreaks.com/topic/242651-overriding-internet-explorer-friendly-http-errors/ Share on other sites More sharing options...
trq Posted July 22, 2011 Share Posted July 22, 2011 If you have access to .htaccess you most likely have access to mod_rewrite. This makes your system completely redundant and very inefficient. Quote Link to comment https://forums.phpfreaks.com/topic/242651-overriding-internet-explorer-friendly-http-errors/#findComment-1246388 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.