IsaacSchlueter Posted June 15, 2004 Share Posted June 15, 2004 First of all, I've only been a customer for a few days, and WOW! TCH is amazing! I'm truly in love. Now on to the problem I have a site that is driven by a bunch of php scripts. I use the extra path info directive to avoid having ?s and &s in the URL. I also prefer to strip the ".php" from my URLs, so that I have something like this: http://www.isaacschlueter.com/blog/2004/05 to show all the posts in the "blog" category, from May, 2004. Of course, the actual file is "blog.php". I was doing this on my previous webhost by putting the following in my .htaccess folder. (It's a little ugly, but it's the only way that I could get it to work.) >RewriteEngine On # If it's just /blah, change it to /blah.php RewriteRule (^[^\./]+)$ $1\.php # If it's /blah/1/2/3, change to /blah.php/1/2/3 RewriteRule (^[^\./]+)/([^\.]*)(.html?)?$ $1\.php/$2$3 # Cleanup Unwanted the RR Tracks, for cases when it's a valid directory # If it's /validdirectory.php/1/2/3, change to /validdirectory/1/2/3 RewriteRule ^(xmlsrv)(\.php)/(.*) $1/$3 RewriteRule ^(htsrv)(\.php)/(.*) $1/$3 RewriteRule ^(admin)(\.php)/(.*) $1/$3 RewriteRule ^(skins)(\.php)/(.*) $1/$3 RewriteRule ^(ari)(\.php)/(.*) $1/$3 RewriteRule ^(httest)(\.php)/(.*) $1/$3 When I do this, it works fine for the URLs. And, for some reason, I can go to http://www.isaacschlueter.com/admin/whatever.php without any problem. But, http://www.isaacschlueter.com/htsrv/login.php gives an Error 500: Internal Server Error. I'm sure that it's some sort of problem with the RewriteRule stuff, because when I remove them, then everything works (but I have to put .php on my urls, of course.) For the time being, I've removed them all, but if you'd like to see what happens, just post here, and I'll upload the .htaccess again. Any ideas? Anyone know of a cleaner way to do what I'm trying to do? If I manage to figure it out, I'll post here to help any lost souls in this predicament in the future Thanks Quote Link to comment Share on other sites More sharing options...
IsaacSchlueter Posted June 15, 2004 Author Share Posted June 15, 2004 I had accidentally dropped a .htaccess file in my htsrv folder, and it was caught in an infinite rewrite! So, everything's working now. Anyhow, this is a much cleaner way to do it. >RewriteEngine On # Extra Super Duper Clean URLs # list all of the valid directory names separated by pipes. RewriteCond %{REQUEST_URI} !^/(folder1|folder2|folder3)(.*)$ RewriteRule (^[^\./]+)$ $1\.php RewriteCond %{REQUEST_URI} !^/(folder1|folder2|folder3)(.*)$ RewriteRule (^[^\./]+)/([^\.]*)(.html?)?$ $1\.php/$2$3 I'm looking into using the -d flag in the RewriteCond to check if it's a valid directory, since hard-coding the dir names is a bit ugly. Of course, it's still not nearly as ugly as rewriting, then re-rewriting back to the way that it was! And, in a way, it's more secure, since I specifically grant access this way to certain dirs, and all others get a 404 for the "missing" php file. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted June 15, 2004 Share Posted June 15, 2004 Glad you were able to solve it. Welcome to the family, Issac! Quote Link to comment Share on other sites More sharing options...
TCH-Don Posted June 16, 2004 Share Posted June 16, 2004 Welcome to the Family Issac and your new home! And thanks for posting that! We really are like family here. So if you need anything, just ask your new family! We love to help Quote Link to comment Share on other sites More sharing options...
DarqFlare Posted June 16, 2004 Share Posted June 16, 2004 Hey Isaac, welcome! mod_rewrite is nice... Quote Link to comment Share on other sites More sharing options...
IsaacSchlueter Posted June 17, 2004 Author Share Posted June 17, 2004 Another way to do this, instead of allowing access to the folders, is to only rewrite certain files... >RewriteEngine On # Extra Super Duper Clean URLs # list all of the file names to rewrite separated by pipes. RewriteCond %{REQUEST_URI} ^/(file1|file2|file3)(.*)$ RewriteRule (^[^\./]+)$ $1\.php RewriteCond %{REQUEST_URI} ^/(file1|file2|file3)(.*)$ RewriteRule (^[^\./]+)/([^\.]*)(.html?)?$ $1\.php/$2$3 Quote Link to comment 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.