Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

URL Rewriting

arvind
Level 4
Level 4

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

 

 

1 Accepted Solution
Arun_Patidar
Correct answer by
Community Advisor
Community Advisor

Can you try with

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

 

you can test at below

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

View solution in original post

0 Replies
Arun_Patidar
Correct answer by
Community Advisor
Community Advisor

Can you try with

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

 

you can test at below

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

View solution in original post

sudesh_16
Level 2
Level 2

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

Ritesh_Mittal
Community Advisor
Community Advisor

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]