LocationMatch Regex | Community
Skip to main content
Level 5
May 19, 2023
Solved

LocationMatch Regex

  • May 19, 2023
  • 2 replies
  • 1012 views

Hi,

 

. In Virtual Host we have added below line. so when we hit like /content/dam/site/abc.pdf . It matches and set Header as below.

<LocationMatch "\.(?i:pdf)$">
ForceType application/pdf
Header set Content-Disposition inline
</LocationMatch>

 

Requirement:

 

If URL is having a selector lets say "pdfdownload" , then it does not set above Header.

 

Could someone help with regex for that.

 

so when we hit something like /content/dam/site/abc.pdf.pdfdownload.pdf, It does not set any Content-Disposition Header.

Thanks in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ShubhanshuSi2

You need to update the regex to exclude URLs containing the "pdfdownload" selector.

<LocationMatch "^/(?!.*pdfdownload).*\.pdf$"> ForceType application/pdf Header set Content-Disposition inline </LocationMatch>

 

2 replies

ShubhanshuSi2Community AdvisorAccepted solution
Community Advisor
May 19, 2023

You need to update the regex to exclude URLs containing the "pdfdownload" selector.

<LocationMatch "^/(?!.*pdfdownload).*\.pdf$"> ForceType application/pdf Header set Content-Disposition inline </LocationMatch>

 

ManviSharma
Adobe Employee
Adobe Employee
May 19, 2023

Hi,

 

To exclude URLs with the "pdfdownload" selector from setting the Content-Disposition header, you can modify the regex pattern in the LocationMatch directive as follows:

 

<LocationMatch "^(?!.*pdfdownload).*\.(?i:pdf)$">

 

This updated regex pattern uses a negative lookahead (?!.*pdfdownload) to exclude URLs containing the "pdfdownload" selector. It ensures that the Content-Disposition header is not set for URLs with the "pdfdownload" selector.

With this modification, when you hit a URL like /content/dam/site/abc.pdf.pdfdownload.pdf, the Content-Disposition header will not be set. However, for URLs like /content/dam/site/abc.pdf, the header will still be applied.