Page 1 of 1
Mod Rewrite issues
Posted: Wed Dec 20, 2006 10:46 am
by John Cartwright
Okay first and foremost, this is probably the weirdest thing I've ever encountered. I don't know why, it just is

Serious thought..
Okay, I am running the latest version of Ubuntu, with Apache 2.0, and yes mod_rewrite module is loaded and works fine for simple specific rules. Now!, heres my problem. I'm trying to route ALL requests to my front controller,
Code: Select all
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
Just ignore those Cond's for now, I know they arn't causing the problem. Now lets say I visit
http://localhost/index/index or for that matter anything that starts with /index/, everything is working like a charm. For debugging, I simply put a exit('here'); to see if the request was made correctly.. which it was. Now, if I visit anything else, such as
http://localhost/index2/ or ihttp://localhost/idontwork/ I am simply getting a 404..
I am not ruling out a server misconfiguration here, so if anyone can shed some light on this disastrous rule.. please do.
Thank you.
Posted: Wed Dec 20, 2006 11:27 am
by RobertGonzalez
This rule
is saying that anything that comes into your domain should be rewritten to index.php/<whatever-was-entered-into-the-url>. Is that what you want? And have you tried throwing some flags out there, like [QSA,L]?
Posted: Wed Dec 20, 2006 11:31 am
by John Cartwright
Everah wrote:s that what you want?
Yes.
And have you tried throwing some flags out there, like [QSA,L]?
Yes, I have just gone through the works.
Posted: Wed Dec 20, 2006 12:02 pm
by RobertGonzalez
Try adding a slash.
Code: Select all
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
Posted: Wed Dec 20, 2006 3:09 pm
by Kieran Huggins
If you're just adding everything as an argument to your front controller, why bother? Isn't the original still accessible via $_SERVER['REQUEST_URI'] anyway?
Cheers,
Kieran
Posted: Wed Dec 20, 2006 3:26 pm
by John Cartwright
I'm going to just recompile Apache with 1.3.. gave up horribly.
Kieran Huggins wrote:If you're just adding everything as an argument to your front controller, why bother? Isn't the original still accessible via $_SERVER['REQUEST_URI'] anyway?
Cheers,
Kieran
That is the point, to direct all requests to a focal point in your application. I don't really understand what your getting at? Why bother with what?
Edit | back to the drawing board, going to have to recompile with Apache 2 again, forgot my new hosts is running Apache2 and want to avoid incompatibilities such as this.
Posted: Wed Dec 20, 2006 3:35 pm
by Luke
I think he means you can do this instead:
Code: Select all
RewriteEngine On
RewriteRule .* index.php
And then access the information you're adding after index.php/ with $_SERVER['REQUEST_URI'] instead
Posted: Wed Dec 20, 2006 3:38 pm
by Kieran Huggins
sorry - I was a bit unclear.
What I think you're doing is redirecting every URL to your front controller at /index.php - and you're having trouble passing the original URL to it as an argument.
My suggestion is to not pass the original URL at all, but rather simply reference it in your script from the $_SERVER['REQUEST_URI'] variable. Even after a mod-rewrite, $_SERVER['REQUEST_URI'] retains the original, unmodified URL.
Cheers,
Kieran
Posted: Wed Dec 20, 2006 3:40 pm
by Kieran Huggins
The Ninja Space Goat wrote:I think he means you can do this instead:
Code: Select all
RewriteEngine On
RewriteRule .* index.php
And then access the information you're adding after index.php/ with $_SERVER['REQUEST_URI'] instead
Yup - that's what I mean exactly!
Wow... I seem to be having trouble with that thing where you type the words in to the other thing and still be clear about the original thing (of which I'm speaking).
This is why I sucked at French... I have enough trouble with English
