views:

195

answers:

6

I'm building a small PHP framework for the websites I create and wanted to know if I can rely on mod_rewrite being availabe on most hosters.

  • Is ist even a good idea using it? There are many good points already (one entry point, "beautiful", readable URLS)

  • Where is it not availabe?

  • Should I include an alternative in the framework if mod_rewrite is not available on that hoster?

+2  A: 

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

thetaiko
I'm talking about my client's hosts.
someone
How does that change the answer? It's still generally available, and you should switch your clients onto a different host if not.
ceejayoz
If you suspect that a client may not have access to mod_rewrite then you should build your framework based on that assumption.
thetaiko
Seriously ceejayoz? Client A: "I want to buy your software, but my hosting company doesn't support mod_rewrite." Response 1: "Too bad! Switch hosts or GTFO" Response 2: "Good thing my software supports an alternative to mod_rewrite!" Which one gets you more clients, I wonder?
Johrn
Even though mod_rewrite really *should* be available on a decent hosting package, Johrn makes a good point there.
Pekka
+2  A: 

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.

Gumbo
+1 the more options you offer, the more chances your product has.
Pekka
A: 
ElAlecs
+2  A: 

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

Alan Storm
A: 

It's available in most servers -- but if you suspect it's not, you should make a dynamic way to fetch links -- you could then have a predefined constant that you modify before everything that says whether or not mod_rewrite is available. You can then fetch the URLs using that constant as the way to determine what happens.

henasraf