php Zend / MVC without mod_rewrite

2020-04-28 23:14发布

问题:

I've seen it mentioned in many blogs around the net, but I believe it shoud be discussed here. What can we do when we have an MVC framework (I am interested in ZEND) in PHP but our host does not provide mod_rewrite? Are there any "short-cuts"? Can we transfer control in any way (so that a mapping may occur between pages)? Any ideas? Thank you :-)

回答1:

Zend framework should work without mod_rewrite. If you can live with your URL:s looking more like "/path/to/app/index.php/controller/action". If you had mod_rewrite you could do away with the "index.php" bit, but it should work with too.

It's all a matter of setting up the routes to accept the index.php part.



回答2:

OK my verdict :-) : I have used successfully zend without mod_rewrite and it's as you've all said site/index.php/controller/action. I knew that before posting this. I've also found out around the net a technique that "pushes" 404 pages to index.php therefore what is not a resource (eg. CSS, image, etc) gets there, with one exception: POST values. So I decided that the next time an application has to be made in the specific server, to ask politely for mod_rewrite. If administrator can not provide it, talk with my boss or if it is for me, switch provider. Generally it is a shame some times that PHP market is so much fragmented (php4, php5, php6, mod_rewrite, mod_auth, mod_whatever), but this is another story...



回答3:

mod_rewrite is almost essential in today's hosting environment..but unfortunately not everyone got the message.

Lots of the large php programs (I'm thinking magento, but most can cope) have a pretty-url fall back mode for when mod_rewrite isn't available.

URLs end up looking like www.site.com/index.php?load-this-page

They must be running some magic to grab the variable name from the $_GET variable and using it as the selector for what module/feature to execute.

In a related note, I've seen lots of messed up URLs in the new facebook site where it's using the #. So links look like www.new.facebook.com/home.php#/inbox/ Clearly we're not meant to see that but it suggests that they're probably parsing the $_SERVER['REQUEST_URI'] variable.



回答4:

If you can find a non-mod_rewrite way to redirect all requests to index.php (or wherever your init script is), you can, as mentioned above, use 'REQUEST_URI' to grab the portion of the address after the domain and then parse it as you like and make the request do what you want it to. This is how Wordpress does it (granted, with mod_rewrite). As long as you can redirect requests to your index page while retaining the same URI, you can do what you need to to process the request.



回答5:

Drupal's rewrite rules translate

http://example.com/path/goes/here

into

http://example.com/index.php?q=path/goes/here

...and has logic to decide which flavor of URLs to generate. If you can live with ugly URLs, this would let you keep all the logic of a single front controller in place w/o relying on URL rewriting.