【发布时间】:2019-09-12 20:39:56
【问题描述】:
我的问题:
我希望能够向我的客户发送mywebsite.com/products 之类的链接,以便他们可以下载.xlsx 文件并查看我在自动取款机上看到的内容。
有什么方法可以创建像“www.mywebsite.com/file”这样的链接,这样当用户访问此 URL 时,浏览器会打开提示下载.xlsx 文件?
这是我的products.html 文件:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=http://mywebsite.com/products.xlsx"/>
</head>
</html>
我已经将products.xlsx 上传到我的服务器。
我注意到如果我使用扩展名.html 访问该网站,它会提示用户下载文件。如果我在没有扩展程序的情况下访问,则会导致 404 错误。
也许是我的.htaccess 配置导致了这种情况?
也许是Options +MultiViews 或HTML RewriteCond..
Options All -Indexes
DirectoryIndex index.php index.htm index.html
RewriteEngine on
RewriteBase /
# ---- Make pages render without their extension in the url
Options +MultiViews
# Force HTTPS on the subdomains/subdirectories login or admin
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^(login|admin)\. [NC]
#RewriteCond %{REQUEST_URI} ^(login|admin)\. [NC,OR]
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force WWW if no subdomain is given
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Remove php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Remove html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
我该如何解决这个问题?
【问题讨论】:
-
是的,一个简单的锚标签应该可以做到这一点
-
嗯..你能解释一下吗?在我的
index.html文件中,我在按钮中使用以下代码来提示用户下载文件:<p><a href="products.xlsx" download class="btn btn-common wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="2000ms">See Products</a></p>。如何设置此代码的锚点并修改我的products.html文件以实现所需的输出? (“自动”提示用户下载文件的 URL) -
这些类混淆了该元素上的问题,因为它们使 Bootstrap 以不同的方式对待
<a>。只需使用简单直接的<a href="something.xlsx">Click here</a> -
好的,
<a></a>属性并不是我的问题。用户可以单击我的按钮并下载文件。我想要实现的是向我的客户发送marketable URL,当他们访问该 URL 时,我的代码会提示它下载文件……而“可销售的 url”是指我不想发送给他们像“mywebsite.com/products.html”这样的链接。我想发送类似“mywebsite.com/products”的内容。
标签: php html .htaccess redirect download