Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!

Dispatcher Rewrite

Avatar

Level 2

Can somebody help me to redirect dispatcher url for below need?

 

https://localhost:8080/content/mysite/home/ca/en/global/search-results.html?rootpath=/ca/en/abc&para...

 

to 

 

https://localhost:8080/ca/en/abc/test (remove Group 1 - /content/mysite/home/ca/en/global/search-results, .html. ?, rootpath= Group 2 - /ca/en/abc&param)

 

 

10 Replies

Avatar

Community Advisor

Hi @Gatsby 

1.Enable the mod_rewrite module in Apache.

2.Add the following rewrite rule to your Apache configuration file:

RewriteEngine On

RewriteRule ^/ca/en/global/search-results/rootpath=(.*)$ /content/mysite/home/ca/en/global/search-results.html?rootpath=$1 [L]

This rule will match any URL that starts with /ca/en/global/search-results/rootpath= and capture the value of rootpath as a group. It will then rewrite the URL to the original URL with the rootpath parameter set to the captured value.

3.Restart Apache to apply the changes.



Avatar

Community Advisor

 

## check if there is a rootpath query param with request
RewriteCond %{QUERY_STRING} ^rootpath=(.*)$
## rewrite the path with 302 redirect. If you don't want user to see the redirect, change R=302 with PT RewriteRule ^/content/mysite/home/ca/en/global/search-results\.html$ /ca/en/global/search-results/rootpath/%1 [R=302,L] ## %1 captures the value of the query string. If you don't need it just replace it with "test" as per your usecase. 

 

Thanks,

Lokesh 

Avatar

Community Advisor

@Gatsby  Is not the URL path not matching with the "/content/mysite/home/ca/en/global/search-results.html"?

Please check the Request URL path and update the RewriteRule to match with the path. 

 

Avatar

Level 2

Some how I can able to achieve the part of my requirement as below:

RewriteCond %{QUERY_STRING} ^rootpath=(.*)&param=(.*) [NC]
RewriteRule ^(.*) %1/%2 [R302,L]

 

Avatar

Community Advisor

Hi @Gatsby 
You can try with below

 

RewriteCond %{REQUEST_URI} ^/content/mysite/home/ca/en/global/search-results\.html$
RewriteCond %{QUERY_STRING} ^rootpath=([^&]+)&param=(.*)$
RewriteRule ^/content/mysite/home/ca/en/global/search-results\.html$ /%1/%2? [R=301,L]

 

Test Link



Arun Patidar

Avatar

Level 2

@arunpatidar @AMANATH_ULLAH There is 404 after using below rule

RewriteCond %{QUERY_STRING} ^rootpath=([^&]+)&param=(.*)$
RewriteRule ^(.*) %1/%2 [R=302,L,QSD]

Screenshot 2024-03-07 at 11.11.13 AM.png

Avatar

Administrator

@Gatsby Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni

Avatar

Administrator

@Gatsby  If you have found out solution yourself, please share it with the community.



Kautuk Sahni