特定文件名 pdf 的 .htaccess 规则
.htacces rule for specific filename pdf
我正在尝试为特定的 Pdf 分配一个规范(基于它们的文件名),同时我需要为所有其他 pdf 分配一个通用的规范。
我实际上在使用这些规则:
<Files The-life-of-RINGO.pdf>
Header add Link '<https://website.com/01/canonical/>; rel="canonical"'
</Files>
<Files Product-new.pdf>
Header add Link '<https://website.com/02/canonical/>; rel="canonical"'
</Files>
<Files Presentation.pdf>
Header add Link '<https://website.com/03/canonical/>; rel="canonical"'
</Files>
<Files The-rulebook.pdf>
Header add Link '<https://website.com/04/canonical/>; rel="canonical"'
</Files>
<Files Adventure-trial.pdf>
Header add Link '<https://website.com/05/canonical/>; rel="canonical"'
</Files>
# PDF Canonical
RewriteRule ([^/]+)\.pdf$ - [E=FILENAME:]
<FilesMatch "\.pdf$">
Header add Link '<https://www.website.com/uploads/%{FILENAME}e>; rel="canonical"'
</FilesMatch>
问题是现在 htaccess 通过应用不同的规则来添加到特定 pdf 的规范。
例如,它在 RINGO.pdf 的生活中添加了:
有没有办法添加条件逻辑来忽略前 5 个文件的通用 pdf RewriteRule?
谢谢。
反其道而行之 - 首先为所有 PDF 设置规范,然后对单个 PDF 使用 set
而不是 add
。
https://httpd.apache.org/docs/2.4/mod/mod_headers.html#header:
add
: The response header is added to the existing set of headers, even if this header already exists. This can result in two (or more) headers having the same name. This can lead to unforeseen consequences, and in general set, append or merge should be used instead.
set
: The response header is set, replacing any previous header with this name. The value may be a format string.
我正在尝试为特定的 Pdf 分配一个规范(基于它们的文件名),同时我需要为所有其他 pdf 分配一个通用的规范。
我实际上在使用这些规则:
<Files The-life-of-RINGO.pdf>
Header add Link '<https://website.com/01/canonical/>; rel="canonical"'
</Files>
<Files Product-new.pdf>
Header add Link '<https://website.com/02/canonical/>; rel="canonical"'
</Files>
<Files Presentation.pdf>
Header add Link '<https://website.com/03/canonical/>; rel="canonical"'
</Files>
<Files The-rulebook.pdf>
Header add Link '<https://website.com/04/canonical/>; rel="canonical"'
</Files>
<Files Adventure-trial.pdf>
Header add Link '<https://website.com/05/canonical/>; rel="canonical"'
</Files>
# PDF Canonical
RewriteRule ([^/]+)\.pdf$ - [E=FILENAME:]
<FilesMatch "\.pdf$">
Header add Link '<https://www.website.com/uploads/%{FILENAME}e>; rel="canonical"'
</FilesMatch>
问题是现在 htaccess 通过应用不同的规则来添加到特定 pdf 的规范。
例如,它在 RINGO.pdf 的生活中添加了:
有没有办法添加条件逻辑来忽略前 5 个文件的通用 pdf RewriteRule?
谢谢。
反其道而行之 - 首先为所有 PDF 设置规范,然后对单个 PDF 使用 set
而不是 add
。
https://httpd.apache.org/docs/2.4/mod/mod_headers.html#header:
add
: The response header is added to the existing set of headers, even if this header already exists. This can result in two (or more) headers having the same name. This can lead to unforeseen consequences, and in general set, append or merge should be used instead.
set
: The response header is set, replacing any previous header with this name. The value may be a format string.