1

I have a requirement where I need to redirect every URL and add trailing / in the end.

Example : www.site1.com/abc should redirect to www.site1.com/abc/.

Forward slash "/" should be added to every URL. How to handle this in Sitecore?

New contributor
Vikram is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
5
  • If you have CDN that supports redirects like Cloudflare, you can handle this there as well. If you want to handle it in Sitecore, you can make use of several redirect modules present in Sitecore marketplace -marketplace.sitecore.net/SearchResults#qr=redirect.
    – Ghanendra
    Sep 22 at 11:17
  • Can't handle at Cloudflare level. Need to Handle at application level. Is there way to handle in SItecore via Some Pipelines. Not using any Modules.
    – Vikram
    Sep 22 at 11:19
  • You can create pipeline after ItemResolver processor and add your logic there. Sep 22 at 11:20
  • 4
    That really should not happen in Sitecore. That's purely wasting resources if you need Sitecore handling this. Use IIS Rewrite module as suggested by Guarav in his answer
    – Marek Musielak
    Sep 22 at 11:21
  • You can add a hook at httprequestbegin pipeline to evaluate incoming URL and do the redirects. Only problem is it will intercept each incoming request which is why we should depend on pipelines as last resort only.
    – Ghanendra
    Sep 22 at 11:25

1 Answer 1

1

You can achieve this by adding below in web.config in the <rewrite> section -

<rule name="Add trailing slash" stopProcessing="true">
  <match url="(.*[^/])$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>
3
  • Can't Use IIS redirects. Is there way to handle in Sitecore.
    – Vikram
    Sep 22 at 10:47
  • Follow this link - stackoverflow.com/questions/1385265/… Sep 22 at 10:51
  • As @marekmusielak mentioned in the comment, this really should not happen in Sitecore. That's purely wasting resources if you need Sitecore handling this. What is the reason for adding in web.config? not Sep 22 at 11:56

Your Answer

Vikram is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.