I’m getting stuck with a mod_rewrite issue, the root folder of my code is in localhost.dev/framework/ and I’m trying to redirect all requests to the index.php in that folder.
All calls such as ‘localhost.dev/framework/testing’ and ‘localhost.dev/framework/testing/another’ successfully send the URI to index.php but if I just call ‘localhost.dev/framework/’ I get a 500 Internal Server Error.
I’ve tried adding “RewriteRule ^$ index.php?url=$1 [QSA,PT]” above my current rewrite rule which allows me to call ‘localhost.dev/framework/’ and that passes in the URI ‘index.php’ but all subsequent requests such as ‘localhost.dev/framework/testing’, etc. will still only pass index.php
Any help with figuring this out would be greatly appreciated!
Turns out my 500 error was caused by including a .php file that contained an open <?php tag without any actual code being executed.
This thread can be closed as the rewrite is functional.
When you move this to a server, you’re going to kill the server by making it test for the mod_rewrite module on EVERY file request.
[rant #4][indent]The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> … </IfModule> wrapper is the same thing in the webmaster world. DON’T BE AN IDIOT! If you don’t know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache’s resources (and should NEVER be allowed on a shared server).[/indent][/rant 4]
Nothing personal … just trying to make sure you (and others) think about the code you use in .htaccess.
Thanks for the advice! I’ve been a programmer forever but just starting to get into server administration and Apache, this was something that never even crossed my mind!
Also, I see this is rant #4… where are the others located?
As the former Team Leader, I was getting Carpal Tunnel Syndrome from repeating the same things over and over. I created the different rants via AutoHotKey which looks at my typing and makes immediate replacements. As you’re curious:
[rant #1][indent]The use of “lazy regex,” specifically the :kaioken: EVERYTHING :kaioken: atom, (.*), and its close relatives, is the NUMBER ONE coding error of newbies BECAUSE it is “greedy.” Unless you provide an “exit” from your redirection, you will ALWAYS end up in a loop![/indent][/rant #1]
[rant #2][indent]The Last flag, [L], is the mod_rewrite equivalent of ; AND } in PHP and JavaScript. If you DON’T use it, that RewriteRule is ANDed with the following mod_rewrite block statement. In other words, good coding habits DO count![/indent][/rant #2]
[rant #3][indent]My purpose for being here is to share knowledge, not to do free coding. I consider requests for free code to be from “script kiddies” and will not respond to them. Take the time and make an effort to learn and you’ll get all the assistance you need![/indent][/rant #3]
Very interesting! However, it makes little sense having that (from Apache’s POV) as ErrorDocument will do the same thing and add the versatility of matching other (than 404) error codes, too, while mod_rewrite adds the versatility of sending the {REQUEST_URI} along in a query string (if that’s what the webmaster wants, i.e., for error handling). Thanks for pointing that out, though, as it’s always nice to add a tool to the collection.
There is one major difference between ErrorDocument 404 and FallbackResource: ErrorDocument automatically reports HTTP status 404, whereas FallbackResource reports HTTP status 200.
You could override the 404 status from ErrorDocument, but this is not something you would normally do in a website, because you wouldn’t start on the premise that the request is a 404 request (rather you’d assume that the request is a 200 request and change it to a 404 request if you can’t find what the visitor is looking for).
In other words, because of the 200 status, FallbackResource behaves more like it’s mod_rewrite equivalent then ErrorDocument does