Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

LocationMatch Regex

Avatar

Level 6

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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>

 

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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>

 

Avatar

Employee Advisor

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.