Expand my Community achievements bar.

SOLVED

Dispatcher URL Rewriting

Avatar

Level 7

for my localhost:80/content/sample-project/us/en.html should point to www.sample-project.com/learn or sample-project/learn how to achieve these scenarios. 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Ronnie09 

You can follow below steps:

In httpd conf file:
ServerName sample-project.com:80

In v-host file under <VirtualHost *:80>: -
ServerName sample-project.com
ServerAlias www.sample-project.com

and then rewrite rule as:
RewriteRule ^/(.*)$  /$1 [PT,L]


View solution in original post

4 Replies

Avatar

Community Advisor

Hi @Ronnie09 ,

1. Add entry in resource mappings at OSGI config in AEM
/config.publish/org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl.xml
resource.resolver.mapping="[/:/,/content/sample-project/us/en:/]"

2. Add Apache server rewrite rules
RewriteRule ^/$ /content/sample-project/us/en.html [PT,NE,L]
RewriteRule ^/(.*)$ /content/sample-project/learn/$1 [PT,NE]

Hope that helps!

Regards,

Santosh

Avatar

Community Advisor

Defining the virtual host configuration and rewrite rule should fix the problem.

Please refer the document below for more information

https://experienceleague.adobe.com/docs/experience-manager-dispatcher/using/configuring/dispatcher-d...

 

Avatar

Community Advisor

@Ronnie09 This can be handle in two steps.

 

First, you would need to assign your local host a domain name 

https://ecompile.io/blog/localhost-custom-domain-name 

 

Second, add a redirect rule in the dispatcher

 

RewriteRule "^/learn$" "https://%{SERVER_NAME}/content/sample-project/us/en.html" [R,L]

 

Hope this helps.

Avatar

Correct answer by
Community Advisor

Hi @Ronnie09 

You can follow below steps:

In httpd conf file:
ServerName sample-project.com:80

In v-host file under <VirtualHost *:80>: -
ServerName sample-project.com
ServerAlias www.sample-project.com

and then rewrite rule as:
RewriteRule ^/(.*)$  /$1 [PT,L]