<filesmatch> for only one page

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 10:00:06

问题


I have a need to have only the home page have the following Filesmatch where .pdf files need to ask before opening up, but other .pdf files in the site (not on the home page) I want to open automatically. Is this the best way to accomplish this?

This is a Wordpress site, latest version, and the home page is a set page. Also, the owner of the site could add more .pdf links within the site so I don't want to complicate it too much where she has to manipulate code every time she adds a file.

Here is what is currently in my .htaccess file:

# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
ErrorDocument 404 /index.php
ErrorDocument 403 /index.php

#BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.dramanotebook.com/$1 [R,L]


<Files 403.shtml>
order allow,deny
allow from all
</Files>

<FilesMatch "\.pdf$">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</FilesMatch>

# END WordPress

Thanks in advance, Jim


回答1:


I was able to accomplish this by using <Files></Files>.

example:

<Files "filenameexample.pdf">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</Files>

The trick is you need to add a <files></files> for each file you want to individually control. There are no options to say "all PDF's on this page be protected, but other pages do something else". Actually, you could..but you would have to put an .htaccess file in each folder to "revert" it back to another way for those extensions. Crazy. Faster just to do the 3 files I needed specifically.

I found none of the information online helpful nor any responses. I just tested a lot.

Jim



来源:https://stackoverflow.com/questions/15581204/filesmatch-for-only-one-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!