noodlehaus/dispatch

mod_rewrite required?

Closed this issue · 4 comments

Great job!

But as far as is understood the library, Apache mod_rewrite is required and I haven´t seen any documentation stating this subject and a simple example of a .htaccess file.

If I'm wrong and apache mod_rewrite is not required, how does the library process the requests that would throw a 404?

For example:
A request for http://site.com/a/b/1
Apache will try to find a subdirectory in the virtual root directory with the path "/a/b/1".
How does dispatch get this request, if the code with the mappings is located in the file "/index.php"?
Thanks.

Hey @waltervi,

Just looked through the 4.x branch for Dispatch and didn't see anything on .htaccess either. Pretty sure the original Dispatch PHP site had a demo .htaccess I used to get started, but it's no longer up far as I can see. Here's the .htaccess I use:

<IfModule mod_rewrite.c>
  RewriteEngine on
  # in this case, our app bootstrap file is index.php
  RewriteRule !\.(js|html|ico|gif|jpg|png|css|woff|eot|svg)$ index.php
</IfModule>

@noodlehaus Documentation on this would probably help clear up a bit of confusion for newcomers to routing in PHP.

I could write up a section on this and issue a pull request if needed?

Hi Brandtley!

I think (IMHO) that this part related to mod_rewrite should be added to the docs, just a little example of an .htaccess file, and say: "mod_rewrite is needed".

I know most people working with a library like this "should have to know/figure out this", but what about someone who is just starting?

I'm writing my own now. And I will post it here later.

Thanks for the fast reply.

=)

Dig it. Something else you can do is run PHP's internal server mechanism as a testing environment for getting your project up and running without worrying about apache until later.

$ php -S localhost:3051 index.php

More info here: http://php.net/manual/en/features.commandline.webserver.php

thanks for raising this. documentation has been updated to include example configurations for both apache and nginx.