Can I rely on mod_rewrite? Can I rely on mod_rewrite? apache apache

Can I rely on mod_rewrite?


mod_rewrite is generally available. If it is not available on your hosts' servers, drop them.


The MOD_REWRITE module is generally avaiable on most Apache hosts these days. However, it's not THAT hard to work around its absence, and by doing so you ensure that people stuck on a/with a host/IT staff who've turned it off, or a host/IT staff running IIS, etc.

Most new frameworks or applications built today use mod_rewrite to intercept all URL requests through a single front loading PHP file (called Bootstrapping, Frontloading pattern, etc.). The URL portion that's not the domain name is parsed into some object, and that object is used whenever you need access to the URL.

When MOD_REWRITE is NOT available, URLs in the form of

http://example.com/index.php/foo/baz/bar

are used instead. A request for the above URL is handled by the index.php file. Then, you can parse one of the the server variables like

$_SERVER['REQUEST_URI'], $REQUEST['PATH_INFO'], etc.

into some object (the same object you'd use if you had mod_rewrite) and use that object whenever you needed access to the URL information.

Either way, the rest of your framework/application just accesses the object, and doesn't have to worry about how the information got in there.

Additional Reading


If you’re developing an application that is publicly available, you should consider that mod_rewrite might not be available and support an alternative. AcceptPathInfo is one.