How to make URL friendly without apache mod_rewrite?

Asked

Viewed 162 times

1

I have a small project to do in the next few days and my client has a cheap, shared hosting that does not allow me to change the settings of apache and is not with mod_rewrite enabled. I would like to find another way to keep Urls friendly and am thinking of architecting an environment where:

http://www.meucliente.com/action/param1/param2/

is replaced by:

http://www.meucliente.com/?/action/param1/param2/

Note the question mark before /action.

From this the index.php will read the superglobal $_SERVER['QUERY_STRING'] to decide what to do. Even a form with POST would be sent to an address that looks like a GET.

<form action="/?/form-action/" method="POST">...</form>

Here comes the real doubt:

In your opinion this looks very gambiarra?
There is another more elegant way to make the URL friendly without the mod_rewrite apache?

  • Can you make htaccess use? Or is it only mod_rewrite that is not enabled? because if you can use htaccess you can create an Handler and have another type of file be interpreted as php...

  • I’ll catch up and research how it does what you suggested, thanks for the tip.

2 answers

2


It is a valid technique for cases where URL rewriting is not available, either by Apache, Nginx, IIS or any other server.

This is called a "false friendly url". Or "fake mod_rewrite". Finally, there is no "official" term. Normally you will find information about the subject if you search for these terms.

Another way of doing it is

http://www.foo.bar/index.php/action/param1/param2/

In fact, it is the same as using the way you presented the question, using the empty argument parameter.

Not everything done with gambiarras represents something bad or amateur.

Popular frameworks have support for this gambiarra as well. There are gambiarras that are useful and good and, this one is sure to be good and useful

However, applying a user-friendly URL when submitting a request using the POST method makes no sense.

  • You are absolutely right, it makes no sense to use this in the POST. Thank you very much for the clarification, exceeded my expectations.

1

Answering your question:

Here comes the real doubt: In your opinion, dear Experienced developers, does this look like a lot of skulking? there is another more elegant way to make the url friendly without the apache mod_rewrite?

No! I do not see gambiarra and based on your needs, I recommend studying better the design patterns: Front Controller or Frontal Controller and Command.

Frontal Controller

The main function of a front-end controller in web-based applications is to encapsulate typical request cycles /rota/despacho/resposta within the limits of an easily consumable API. Repeating what your friend told you above, the URL would be something like: http://www.foo.bar/index.php/action/param1/param2/.

This is the path you find yourself on. With the standards mentioned, you will gain in flexibility and reuse without code redundancy. Your index php. would be responsible for handling all requests, based on the specific request, instantiating other objects and calling methods to handle the specific tasks required. Taking advantage to treat other things if necessary, for example: security and internationalization.

Encapsulation of all requests through a single entry point is certainly an efficient way to implement a command-based mechanism. In the most basic examples, you will see some instructions for switch to forward and dispatch requests, although in production it may be necessary to resort to more complex implementations.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.