how to skip url shortning for some specfic path. - AEM dispatcher | Community
Skip to main content
New Participant
January 4, 2023
Solved

how to skip url shortning for some specfic path. - AEM dispatcher

  • January 4, 2023
  • 3 replies
  • 2714 views

Hi All,

 I have written some rewrite rules for shortening the URL.

RewriteRule ^/content/we-retail/de/de/(.*.html)$ https://%{SERVER_NAME}/$1 [NE,R=301,L]
RewriteRule ^/(.*.html)$ /content/we-retail/de/de/$1 [PT,L]

with this rule, I am able to short URL   from this ( /content/we-retail/de/de/plp.html)  to (/plp.html).

But I want this rule should not work on some specific path.

ex: if someone is hitting this page.  ---   > /content/test/de/de/plp.html .

it should exclude this rule.

so I have added a rule to skip the condition but somehow it's not working 

 

# skip url shortning   condition  for test
RewriteCond %{REQUEST_URI} !^/content/test/de/de/

Could you please help me how to exclude some paths in the rewrite rule?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mohit_KBansal

could you please help me with the rule how to add skip flags


The skip flag is used with the Apache mod_rewrite module in the Apache HTTP Server to control whether certain rewrite rules are applied or skipped. The skip flag is commonly used in conjunction with the RewriteCond directive to conditionally skip certain rewrite rules based on the result of a test.

For example, you might use the skip flag to skip the execution of a rewrite rule if the request is coming from a specific IP address. Here's an example of how you would use the skip flag in a .htaccess file to skip a rewrite rule for requests coming from the IP address 127.0.0.1:

 

RewriteEngine On RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$ RewriteRule ^(.*)$ - [S=1] RewriteRule ^(.*)$ /new-location/$1 [L]

In this example, the RewriteEngine directive is used to turn on the rewrite engine, the RewriteCond directive is used to check if the IP address of the remote client matches 127.0.0.1 and if so, the RewriteRule with the S flag will be applied. That will skip the next rule and no further rules will be processed.

3 replies

cshawaus
New Participant
January 10, 2023

@raushan123 If I am understanding correctly you want your second rule to be ignored when the request URI begins with /content/test/de/de/.

RewriteRule ^/content/we-retail/de/de/(.*.html)$ https://%{SERVER_NAME}/$1 [NE,R=301,L]

RewriteCond %{REQUEST_URI} !^/content/test/de/de/
RewriteCond %{REQUEST_URI} !^/content
RewriteRule ^/(.*.html)$ /content/we-retail/de/de/$1 [PT,L]

Based on what you have provided, this configuration should what you need. It is difficult to tell if this is what you have already without a full example of this bit of your configuration.

While on the topic of conditions, I'll also recommend you have a condition that prevents your second rule from accepting /content requests. This will help prevent issues whereby the path is duplicated in the rewrite.

Suraj_Kamdi
New Participant
January 4, 2023

@raushan123 You can also use etc/mapping in order to skip URL shortening. Just go through this documentation from Adobe https://helpx.adobe.com/in/experience-manager/kb/multi-domain-management-aem-mappings-for-url-shortening---aem-6-.html 

New Participant
January 4, 2023

HI @ 

 could you please guide me, how you want to add another entry for (/content/test/de/de)

inside etc map . so that we can skip the url shortening for  (/content/test/de/de)

Right now in the etc map i have entry for we-retail

 

Note - I have only one domain, I don't have another domain for  (/content/test/de/de).

 

Mohit_KBansal
Employee
January 4, 2023

@raushan123 Try the below rule

 

RewriteCond %{REQUEST_URI}   !^/content/test/de(.*) [NC]
RewriteCond %{REQUEST_URI}   ^/(.*.html)$
RewriteRule ^/(.*)$ /content/we-retail/de/de/$1 [PT,L]

 

New Participant
January 4, 2023

HI @mohit_kbansal 

could you please explain about these rule?

 

RewriteCond %{REQUEST_URI}   !^/content/test/de(.*) [NC]

 with this, you are skipping the condition

 

and what the use of the below rule is and why I need to add this.

RewriteCond %{REQUEST_URI}   ^/(.*.html)$
RewriteRule ^/(.*)$ /content/we-retail/de/de/$1 [PT,L]
Mohit_KBansal
Employee
January 4, 2023

So, in simple language, the rules are to check

  • If url does not start with path "/content/test/de"
  • AND url should have (.html) extn
  • THEN
  • add context path "/content/we-retail/de/de/" to url and pass through it for further processing.

So we are adding context path to all ".html" urls except "/content/test/de"