Now when you know how to configure basic parameters of the dispatcher, it is time to poke into more advanced ways of using it, which would certainly be necessary on production and very useful during the development.
Below I’m describing a few useful tools for advanced using of the dispatcher:
- static web servers tools
- rewrite module
- AEM tools for mappings
- repository mappings tree /etc/map
- ResourceProvider Interface
You may enable rewrite module by uncommenting next line in your httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
Initial settings for rewrite module may look like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog "logs/rewrite.log"
RewriteLogLevel 9
# your rule 1
# your rule 2
…
# your rule n
</IfModule>
Simple example of using rewrite module:
RewriteRule ^/en(.*)\.html$ /content/geometrixx/en$1.html [R]
This rewrite rule provides external redirect.
Detailed and useful documentation: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
Repository mappings tree /etc/map
Resource mapping is used to define redirects, vanity URLs and virtual hosts for AEM:
- /etc/map - resource mappings tree;
- /etc/map/http - resource mappings for http requests.
Mappings definitions of your AEM instance are at http://host:port/system/console/jcrresolver
Example: mapping that prefixes any request to http://localhost:4503 with /content prefix:
- Create node under /etc/map/http with type “sling:Mapping” with name “localhost_any”;
- Add properties to this node:
- Name “sling:match”, type “String”, value “localhost.4503/”;
- Name “sling:internalRedirect”, type “String”, value “/content/”.
This mapping will handle a request such as http://localhost:4503/geometrixx/en/products.html as if http://localhost:4503/content/geometrixx/en/products.html is requested. This example brokes requests to clientlibs and to other resources are placed outside of /content resource tree.
Detailed and useful documentation:
ResourceProvider interface
You may use ResourceProvider interface for creation of your own resource trees.
public interface ResourceProvider {
Resource getResource(ResourceResolver var1, String var2);
Iterator<Resource> listChildren(Resource var1);
}
You may set root paths for your implementation of the ResourceProvider:
@Properties({
@Property(
label = "Root paths",
description = "Root paths this Sling Resource Provider will respond to",
name = ResourceProvider.ROOTS,
value = {"/content/mount/samples"})
})
Detailed and useful documentation: https://sling.apache.org/documentation/the-sling-engine/resources.html
Summary
Above mentioned three tools give advanced abilities to you for using dispatcher:
- httpd rewrite module;
- AEM mappings tree;
- ResourceProvider interface.
We have made only a brief look of these tools. If you want to use them effectively then you need to learn corresponding detailed documentation for each tool.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.