URL rewriting
The adventure php framework enables you, to operate web pages or applications in url rewrite mode or
in normal mode. URL rewriting means, that URL params are separated by "/" instead of "&" and "=". This
request layout pretends, that the requested ressource is located in a folder path. Another side effect
is, that search engines tend to scan slash URLs more likely. Please note, that this technique does
not supersede normal search engine optimization.
If you use the URL rewrite mode, please be aware, that the bootstrap file (e.g.
index.php)
must be located in the
DOCUMENT_ROOT of your webserver or any VHOST. Otherwise, the
assignment of params and values can not be guaranteed.
Using the URL rewrite mode a
.htaccess file must be created. The following code box
shows you an example, that can be used with the bigger part of your applications:
APF-Template
# start mod_rewrite
RewriteEngine on
# exclude some directories
RewriteCond %{REQUEST_URI} !^(\/frontend) [NC]
# define the rule itself. Every request that is not matching the exception list is
# redirected to the index.php file
RewriteRule !(index\.php|\.css|\.jpe?g|\.png|\.gif|\.ico)$ /index.php?query=%{REQUEST_URI}&%{QUERY_STRING} [NC,L]
Please note, that the definition
APF-Template
/index.php?query=%{REQUEST_URI}&%{QUERY_STRING}
must remain unaffected. It defines the param, that is used by the
PageControllerInputFilter and
FrontControllerInputFilter
to analyze the URL parameters and write them to the
$_REQUEST-Array. The exception list
APF-Template
!(index\.php|\.css|\.jpe?g|\.png|\.gif|\.ico)$
can be manipulated as desired.
To use the framework in URL rewriting mode it is necessary to switch the registry paramater
URLRewriting in the
apf::core namespace to
true.
This can be achieved by adding
PHP-Code
Registry::register('apf::core','URLRewriting',true);
to your bootstrap file.
While using the URL rewriting mode, the following hints should be kept in mind:
- Ressources like images, css files or java scripts must be addressed absolutely.
-
Modules, written for both modes must be aware of the two flavours. If you need to knwo about the
current URL layout you can retrieve this information from the registry.
-
If you are using more than one bootstrap file, please add it to the exception list in the
.htaccess file.
In order to apply url rewriting without changing an application, the framework brings a
output filter, that
rewrites links automatically. In order to explicitly exclude links, the link attribute
linkrewrite can be set to
false. As of release 1.10,
mailto: links are excluded by default.
Comments
Do you want to add a comment to the article above, or do you want to post additional hints? So please click
here. Comments already posted can be found below.
There are no comments belonging to this article.