As we have seen from the section Submitting data to web applications powered by Mivec Framework, calling web applications powered by Mivec Framework is somehow a bit complex. Such URL
http://example.com/MivecServlet.php?____mivec_action____=Login&userID=user&password=secret
is not friendly for users.
To solve this problem, Mivec Framework comes along with two methods that can make more user friendly URLs, by hiding the ____mivec_action____ and embed the action name as the requesting file name.
Note: the methods mentioned below are specific to Apache httpd only.
If all initial tests passed during the initial environment test, it means mod_rewrite is already available, and you can customize the URL using .htaccess.
There’s a .htaccess file comes along with Mivec Framework’s distribution. With the out-of-the-box settings, the above URL can also be called using
http://example.com/Login.htm?userID=user&password=secret
If we want to execute a command inside the Login Action, for example, local(), the URL will then be
http://example.com/Login.local.htm?userID=user&password=secret
If you need the .htm extension, in favor of the static web pages, you have to edit .htaccess. Open it, look for this line:
RewriteRule ^(.*)\.htm$ MivecServlet.php?____mivec_action____=$1 [QSA]
And change the htm to the extension you need. If you do not do so, all requests that end with .htm will be intercepted, and delegated to MivecServlet.php!
If mod_rewrite is not enabled, but you can still access the initial environment test page, it means you can still use .htaccess to override the settings. Then you can use MivecServlet (without the .php extension).
With the out-of-the-box settings, the above URL can also be called using
http://example.com/MivecServlet/Login?userID=user&password=secret
If we want to execute the command local() inside the Login Action, the URL will then be
http://example.com/MivecServlet/Login.local?userID=user&password=secret
You may change the name of MivecServlet to your needs. However, remember to change the section in .htaccess:
<FilesMatch "MivecServlet"> ForceType application/x-httpd-php </FilesMatch>
from MivecServlet to the changed file name.
If you will be using the modifications above, remember that all static resources which are referenced in view templates may also be affected. For example, using MivecServlet’s approach, request URLs are prefixed with /MivecServlet/. For the view templates, if we have reference to images using relative paths, like
<img src="images/login.png" width="56" height=56" alt="Login" title="Login">
browsers will interpret such URL as
http://example.com/MivecServlet/images/login.png
which breaks your page. So you have to change the above <img> tag to
<img src="http://example.com/images/login.png" width="56" height=56" alt="Login" title="Login">
The same rule also apply to enabling friendly URLs using mod_rewrite.
« Prev: Working with Views and View Templates Next: Session Handling »