Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

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

Avatar

Level 4

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?

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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.

View solution in original post

10 Replies

Avatar

Employee Advisor

@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]

 

Avatar

Level 4

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]

Avatar

Employee Advisor

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"

Avatar

Level 4

sorry, actually, this is not my requirement.

let me explain one more time.

right now below rule is added in the rewrite rule file.

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]

I want to skip this rule if someone is hitting  -- > /content/test/de/plp.html.

so how to skip the above rule

 

Avatar

Level 4

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

Avatar

Correct answer by
Employee Advisor

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.

Avatar

Community Advisor

@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-shorte... 

Avatar

Level 4

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

raushan123_0-1672845491430.png

 

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

 

Avatar

Level 3

@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.