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?
Solved! Go to Solution.
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.
@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]
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]
So, in simple language, the rules are to check
So we are adding context path to all ".html" urls except "/content/test/de"
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
You should try Apache Skip flag [1], it works as if-else condition.
[1] https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_s
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.
@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...
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).
@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.
Views
Likes
Replies
Views
Likes
Replies