Help - Search - Members - Calendar
Full Version: .htaccess brain fart
Forums > Resource Center > Webmasters' Corner
fixtatik
I must have hit my head or something, because I can't figure this out for the life of me. I've been doing some work on my site, and I realized if someone goes to site.com/folder/ and the folder doesn't exist, then I get a 404 error. I'd rather have Apache strip the slash at the end and just return site.com/folder, which is a page.

Right now I have:
CODE
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

...which is doing a grand job of rewriting everything I want rewritten, except for folders that don't exist.

Regex masters, any ideas?
mipadi
Completely a guess, but I think you want the last line to be

CODE
RewriteRule (.*) index.php [L]


The '*' means "zero or more characters", where as a '.' just means any one character (assuming Apache's regexps are the same as in other regexp libraries).
fixtatik
Nope, nothin' doin'. :\
I figured I'd be able to drop a 301 redirect in there to send non-existant folders to the index.php page without the slash, but that didn't work either.

Go figure, I managed to get it to do what I want by putting a 301 redirect in PHP, but I hate not having URL rules away from the .htaccess file. That, and it would probably be faster going through Apache than the check I currently have in PHP.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.