ostrich99 Posted May 3, 2005 Posted May 3, 2005 All, Instead of creating a bunch of subdirectories, I'd like to be able to rewrite the URL using PHP or some other scripting language. For Example: User enters: http://www.domainname.com/subdir I'd like to strip off the subdir characters, look up a matching record in a mysql database, and then redirect the user to http://www.domainame.com/display/index.php?record=77 where record 77 is the record id of the subdir matched via the database. Not sure if that makes much sense or not. My first thought is using a custom 404 error message to parse this out. Can i make the 404 error message a PHP script? or must it be a .shtml script as that's showing as the default in the control panel. Any other suggestions? ostrich99 Quote
ostrich99 Posted May 3, 2005 Author Posted May 3, 2005 I guess I should clarify too. If I can make the custom error file a PHP file, then I my php skills are probably sufficient. If not, then I'll need some guidance from the group here on how to do this. Ostrich99 Quote
TCH-Bruce Posted May 3, 2005 Posted May 3, 2005 Normally you use the mod_rewrte module of the server by adding rules and statements to your .htaccess file. Here is a link to a url rewriting tutorial that may help. Quote
ostrich99 Posted May 3, 2005 Author Posted May 3, 2005 Bruce, Thanks for the link. I think this might get me to where I need to be. If I understand the tutorial write, I think I could just rewrite the URL to pass the subdir they used to another PHP script which does the database access,etc. Time to refresh myself on regular expressions. Too many years of windows programing. Ostrich99 Quote
TCH-Bruce Posted May 3, 2005 Posted May 3, 2005 Not sure, I am a noob when using rewrites in the .htaccess file but I am sure some of our other members that know how to do will chime in. Quote
owatagal Posted May 4, 2005 Posted May 4, 2005 (edited) You can use PHP on a 404 file. You just want to add a line to your .htaccess page that says ErrorDocument 404 /yourpage.php [Edited out the .htaccess stuff because I reread the post and I don't think I was answering what it needed to do.] Edited May 4, 2005 by owatagal Quote
borfast Posted May 4, 2005 Posted May 4, 2005 ostrich99, if you can, make it a "subdirectory"... ok let me explain this better: instead of making it work with www.domain.com/subdir make it work with www.domain.com/sub/dir. This way you can create a rewrite rule that redirects only those "special" links and leaves all the rest alone, while creating a redirect rule for www.domain.com/subdir would have to catch every link going to your website. Quote
ostrich99 Posted May 19, 2005 Author Posted May 19, 2005 All, Well I got this sorta working using a custom php error page for a 404. Big issue though is that by default, IE will not show custom error pages. There is a setting in IE called "Show Friendly HTTP error messages" and it just shows a generic cannot be found message. Really sucks as this script I wrote works really well, and works fine in Firefox, etc. SO, it looks like I have to go the .htaccess route. Anyone have any idea of I'll have similar issues with that method? Ostrich99 Quote
Guest Serpentine Posted May 19, 2005 Posted May 19, 2005 .htaccess will work fine, I use mine for that. IE wont show the other one most likely because the file size it too small. Quote
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.