URL Rewriting

Avatar

Avatar
Boost 5
Level 2
arvind
Level 2

Likes

7 likes

Total Posts

34 posts

Correct reply

0 solutions
Top badges earned
Boost 5
Give Back
Ignite 1
Boost 3
Validate 1
View profile

Avatar
Boost 5
Level 2
arvind
Level 2

Likes

7 likes

Total Posts

34 posts

Correct reply

0 solutions
Top badges earned
Boost 5
Give Back
Ignite 1
Boost 3
Validate 1
View profile
arvind
Level 2

14-06-2021

Hello Team,

 

Hope you are doing fine.

 

I need one small help regarding URL rewriting in Apache dispatcher :

 

REQUIREMENT:

 

This is my current rule for home page and other pages, it works fine.

# Homepage
#Homepage
RewriteRule ^/$ /en.html [R,L,ENV=REDIRECTCACHE:1]


# Base path prepend
RewriteCond %{REQUEST_URI} !^/dispatcher/.*
RewriteCond %{REQUEST_URI} !^/libs/.*
RewriteCond %{REQUEST_URI} !^/content/mysite-uk/.*
RewriteCond %{REQUEST_URI} !^/content/experience-fragments/.*
RewriteCond %{REQUEST_URI} !^/content/dam/.*
RewriteCond %{REQUEST_URI} !^/etc/.*
RewriteCond %{REQUEST_URI} !^/etc.clientlibs/.*
RewriteCond %{REQUEST_URI} !^/conf/.*
RewriteCond %{REQUEST_URI} !^/bin/.*
RewriteCond %{REQUEST_URI} !^/system
RewriteCond %{REQUEST_URI} !^/.well-known/.*
RewriteCond %{REQUEST_URI} !^/error/.*
RewriteCond %{REQUEST_URI} !^/robots.txt
RewriteCond %{REQUEST_URI} !^/BingSiteAuth.xml

RewriteRule ^(.*)$ /content/mysite-uk$1 [PT,QSA]

 

Now my new requirement is to add a keyword "cmsapp" between domain and main url.

for example:
1) To access home page, now, It should be like that

https://<domainName>/cmsapp --It should open /content/mysite-uk/en.html

Similarly,

2) for other pages,

https://<domainName>/cmsapp/product/coffee ----- It should open /content/mysite-uk/product/coffee.html

 

 

Could some one help me out please.

 

Regards,

AP

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,462 likes

Total Posts

3,329 posts

Correct reply

949 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,462 likes

Total Posts

3,329 posts

Correct reply

949 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

14-06-2021

Can you try with

RewriteRule ^/?cmsapp/(.*)$ /content/mysite-uk/$1.html [PT]

 

you can test at below

https://technicalseo.com/tools/htaccess/?share=ewogICJodGFjY2VzcyI6ICJSZXdyaXRlUnVsZSBeLz9jbXNhcHAvK...

Answers (3)

Answers (3)

Avatar

Avatar
Boost 5
Level 7
Ritesh_M
Level 7

Likes

179 likes

Total Posts

142 posts

Correct reply

45 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 7
Ritesh_M
Level 7

Likes

179 likes

Total Posts

142 posts

Correct reply

45 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Ritesh_M
Level 7

14-06-2021

Hi @arvind ,

 

Basically below is what you want

 

RewriteRule ^/?old_directory/([a-z/.]+)$ new_directory/$1 [PT,QSA]

 

We added QSA, because we do not want to discard query string.

So the final entry which should work should be-


RewriteRule ^/?cmsapp/(.*)$ /content/mysite-uk/$1.html [PT,QSA]

Avatar

Avatar
Validate 1
Level 1
sudesh_16
Level 1

Likes

4 likes

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
sudesh_16
Level 1

Likes

4 likes

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
sudesh_16
Level 1

14-06-2021

Hi @arvind ,

 

For this, you need to do 2 parts;

1. Write http rule in dispatcher.

  •   if there is no url then redirect is it /cmsapp.
  •   if there is url then append the remaining part of the url(leaving domain) at the end of custom url something like cmsapp/$1.

2. Since cmsapp doesnt exist  so add resource resolver mapping configuration in JcrResourceResolverFactory so that syntheic url resolves to correct resource.

 

Keep in mind, for step 1 also test urls with selectors and query strings.

 

Thanks,

Sudesh

Avatar

Avatar
Give Back 10
MVP
Varun_Shakya
MVP

Likes

124 likes

Total Posts

97 posts

Correct reply

24 solutions
Top badges earned
Give Back 10
Ignite 3
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Give Back 10
MVP
Varun_Shakya
MVP

Likes

124 likes

Total Posts

97 posts

Correct reply

24 solutions
Top badges earned
Give Back 10
Ignite 3
Ignite 1
Give Back 5
Give Back 3
View profile
Varun_Shakya
MVP

14-06-2021