Skip to content

Commit

Permalink
Merge pull request #283 from YegorKozlov/master
Browse files Browse the repository at this point in the history
Redirect Manager support for rewrite map
  • Loading branch information
YegorKozlov authored Dec 20, 2024
2 parents 9c76be9 + f4b6939 commit f3f35d4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 14 deletions.
27 changes: 13 additions & 14 deletions _acs-aem-commons/features/redirect-manager/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ last-updated-release: 5.4.0

## Purpose

Redirect Manager allows content authors to maintain and publish redirect configurations from AEM.
Support for redirects is implemented as a servlet filter which evaluates redirect configurations and issues a 302 or 301
respectively in case of a matching incoming request url.
Redirect Manager allows content authors to maintain and publish redirect configurations from AEM.
Support for redirects is implemented as a servlet filter which evaluates redirect configurations and issues a 302 or 301
respectively in case of a matching incoming request url.

## Features
* AEM as a Cloud Service compatible
Expand All @@ -29,7 +29,8 @@ respectively in case of a matching incoming request url.
* [Rewriting Location header](./subpages/mappings.html)
* [Advanced Configuration](./subpages/advanced.html)
+ [Searching over Redirects](./subpages/search.html)
+
+ [Redirecting in Dispatcher with Apache httpd RewriteMap Directive](./subpages/rewritemap.html)

## Getting Started with Redirect Manager

### Configuration
Expand All @@ -50,7 +51,7 @@ To enable redirects create a configuration for PID `com.adobe.acs.commons.redire
To access Redirect Manager, open the main AEM menu from the link in the upper-left and select Tools » ACS AEM Commons » Manage Redirects
or navigate to http://localhost:4502/apps/acs-commons/content/redirect-manager/redirects.html

You will see a list of available redirect configurations. The default global configuration (`/conf/global`) is created
You will see a list of available redirect configurations. The default global configuration (`/conf/global`) is created
automatically by ACS Commons and it is a good start to put your redirects.

![/conf/global](images/conf_global.png)
Expand All @@ -60,7 +61,7 @@ Click on `/conf/global` to start managing redirect configurations

![Manage Redirects](images/manage-redirects.png)

Click the _"+ Redirect Configuration"_ button to add a redirect rule, e.g.
Click the _"+ Redirect Configuration"_ button to add a redirect rule, e.g.

| Source | Target | Status Code |
|-------------------------------------|-------------|-------------|
Expand All @@ -70,29 +71,27 @@ Click the _"+ Redirect Configuration"_ button to add a redirect rule, e.g.

Redirects are supported for pages and assets. You can match by exact path or by a regular expression.
It is also possible to evaluate the source based on the request URI. This can be configured for each redirect configuration separately.
Enabling this allows evaluation of request specific data (ie. suffix).
Enabling this allows evaluation of request specific data (ie. suffix).

Target can include back-references ($N) to the regex pattern which will be replaced by the contents of the Nth group of
the regex match.

See [Manage Redirects](./manage.html) for more information.

### Replicate
### Replicate

On the "Manage Redirects" page switch to the *Publish* tab and click the 'Publish Redirect Configurations' button
On the "Manage Redirects" page switch to the *Publish* tab and click the 'Publish Redirect Configurations' button
to replicate your redirects to the publish instances.

![Publish Configurations](images/publish.png)

### Testing
### Testing

Navigate to http://localhost:4503/content/we-retail/us/en/contact-us.html which should return
a 302 redirect to http://localhost:4503/content/we-retail/us/en/about-us.html :
Navigate to http://localhost:4503/content/we-retail/us/en/contact-us.html which should return
a 302 redirect to http://localhost:4503/content/we-retail/us/en/about-us.html :

```shell
$ curl -I http://localhost:4503/content/we-retail/us/en/contact-us.html
HTTP/1.1 302 Found
Location: /content/we-retail/us/en/about-us.html
```


63 changes: 63 additions & 0 deletions _acs-aem-commons/features/redirect-manager/subpages/rewritemap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
layout: acs-aem-commons_subpage
title: Search
redirect_from: /acs-aem-commons/features/redirect-manager/manage.html
---

## Redirecting in Dispatcher with Apache httpd RewriteMap Directive

> [!NOTE]
> This feature requires AEMaaCS version 18311 or higher and ACS AEM Commons version 6.10.0 or higher.
Since ACS AEM Commons v6.10.0, Redirect Manager supports [Pipeline-free URL Redirects](https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/content-delivery/pipeline-free-url-redirects) in Dispatcher.

When this option is used, Redirect Manager compiles redirects into a text file, e.g. http://localhost:4502/conf/my-site/settings/redirects.txt, which is further used by Dispatcher to convert into the [RewriteMap](https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritemap) and evaluate the redirect rules in Apache, without requests hitting AEM at all.

#### http://localhost:4502/conf/my-site/settings/redirects.txt
```
# Redirect Map File
/legacy/page1 /en/page1
/legacy/page2 /en/page2
/legacy/page3 /en/page3
```


### Configuration

To enable pipeline-free URL redirects you need to update your dispatcher configuration. Make sure you use the [flexible mode file structure](https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/content-delivery/validation-debug#flexible-mode-file-structure).

In the simplest case you will need to touch two files:

#### Redirect Map File
```
+src
+ conf.d
+ rewrites
- rewrite.rules # defines the redirect rules
+ opt-in
- managed-rewrite-maps.yaml # tells Dispatcher what redirect configurations to pull from Redirect Manager
```


#### managed-rewrite-maps.yaml
```yaml
maps:
- name: my-site-301.map
path: /conf/my-site/settings/redirects.301.txt
- name: my-site-302.map
path: /conf/my-site/settings/redirects.302.txt
```
The `301|302` selector filters the output by status code.
Dispatcher will sync these configuartions into the local storage under the *fixed* location `/tmp/rewrites/`, and then you can reference them in the rewrite rules.

#### rewrite.rules
```
# RewriteMap from managed rewrite maps
RewriteMap my-site-301.map dbm=sdbm:/tmp/rewrites/my-site-301.map
RewriteCond ${my-site-301.map:$1} !=""
RewriteRule ^(.*)$ ${my-site-301.map:$1|/} [L,R=301]

RewriteMap my-site-302.map dbm=sdbm:/tmp/rewrites/my-site-302.map
RewriteCond ${my-site-302.map:$1} !=""
RewriteRule ^(.*)$ ${my-site-302.map:$1|/} [L,R=302]
```

0 comments on commit f3f35d4

Please sign in to comment.