Hi Team, @EstebanBustamante @Raja_Reddy ,
I want to hide my servlet paths so that I need to write rewrites at dispatcher.
Currently client is calling the api in below format
Path Based: http://localhost:4502/bin/test/v1/content?type=page
Resource based: http://localhost:4502/content/test/servlets/fruits.banana.json?type=58&color=yellow
here fruits is a servlet resource node and sling:resourceType is fruits/test/servlets.
I have registered servlet resource type as fruits/test/servlets and with selectors banana and extension as json. Like this I have many servlets with same resource type and multiple selectors.
I want to mask actual servlet URLs so that,
now the client will call API in below format.
Path Based: http://localhost:4502/api/v1/content?type=page
The above URL should internally call original servlet i.e. http://localhost:4502/bin/test/v1/content?type=page
Resource based: http://localhost:4502/mask.banana.json?type=58&color=yellow
The above URL should internally call original servlet i.e. http://localhost:4502/content/test/servlets/fruits.banana.json?type=58&color=yellow
I am writing rewrites in mod_rewrite module as below.
Path based: RewriteRule ^/api/v1/(.*)$ /bin/test/v1/$1?type=page [QSA,PT,L]
Resource based: RewriteRule ^/mask.(.*)$ http://localhost:4502/content/test/servlets/fruits.$1?type=58&color=yellow [QSA,PT,L]
Using QSA flag to pass the query params from proxy servlet to actual.
The above rules not giving expected result. Please suggest how can I achieve this
Thanks!
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Please hit and see if /content/test/servlets/fruits.banana.json working for you.
Also, check path should be allowed and json as an extension is also must be allowed in your dispatcher.
Above rule is working in my local
<VirtualHost *:80>
<Directory "C:/location">
<IfModule disp_apache2.c>
ModMimeUsePathInfo On
# enable dispatcher for ALL request. if this is too restrictive,
# move it to another location
SetHandler dispatcher-handler
</IfModule>
Options FollowSymLinks Includes
AllowOverride None
AddOutputFilter INCLUDES .html
</Directory>
ProxyRequests off
ProxyPreserveHost On
LimitRequestFieldSize 32768
AllowEncodedSlashes NoDecode
RewriteEngine On
RewriteRule ^/mask\.(.*)$ /content/test/servlets/fruits.$1 [QSA,PT,L]
</VirtualHost>
To achieve the desired masking of servlet URLs using Apache's mod_rewrite module, you can modify your rewrite rules as follows:
# Path based masking
RewriteRule ^/api/v1/(.*)$ /bin/test/v1/$1?type=page [QSA,PT,L]
# Resource based masking
RewriteRule ^/mask\.(.*)$ /content/test/servlets/fruits.$1 [QSA,PT,L]
Views
Replies
Total Likes
Hi @Imran__Khan ,
I tried the rules but I am getting below error
Cannot serve request to /mask.banana.json in /apps/sling/servlet/errorhandler/404.jsp
Views
Replies
Total Likes
Please hit and see if /content/test/servlets/fruits.banana.json working for you.
Also, check path should be allowed and json as an extension is also must be allowed in your dispatcher.
Above rule is working in my local
<VirtualHost *:80>
<Directory "C:/location">
<IfModule disp_apache2.c>
ModMimeUsePathInfo On
# enable dispatcher for ALL request. if this is too restrictive,
# move it to another location
SetHandler dispatcher-handler
</IfModule>
Options FollowSymLinks Includes
AllowOverride None
AddOutputFilter INCLUDES .html
</Directory>
ProxyRequests off
ProxyPreserveHost On
LimitRequestFieldSize 32768
AllowEncodedSlashes NoDecode
RewriteEngine On
RewriteRule ^/mask\.(.*)$ /content/test/servlets/fruits.$1 [QSA,PT,L]
</VirtualHost>
Hi @Imran__Khan ,
It's my bad , those rules didn't saved in my rules file hence rewrites were not working. Now I have saved them properly and restarted httpd then it worked. below is the updated one.
# Path based masking
RewriteRule ^/api/v1/(.*)$ /bin/test/v1/$1?type=page [PT,L]
# Resource based masking
RewriteRule ^/mask\.(.*)$ /content/test/servlets/fruits.$1 [PT,L]
I have removed QSA flag as it's not required because query params are automatically transferring to actual API. Thanks @Imran__Khan
Views
Replies
Total Likes