I am new at web developing, I was trying to create download link for a file. This is the code:
<a href="http://symphonyrecords.ir/ARTISTS/Sasan-Khan-Namoondi/SasanKhan-Namoondi[320].mp3" target="_blank" download="SasanKhan-Namoondi[320]">
<button class="downBtn1">Download</button></a>
But when I click the link the file starts downloading inside the browsers not in IDM. (I have tested other links from websites and there was no problem). Should I do something in the meta tag or something ?
After one day research and strangling i found the answer ... I just add onclick method and put the file link with www inside windows.open like this :
<a onclick="window.open ('http://www.symphonyrecords.ir/ARTISTS/Sasan-Khan-Namoondi/SasanKhan-Namoondi[320].mp3', ''); return false" href="javascript:void(0);" download>
<button class="downBtn1">Download</button></a>
This is not the best answer but it will do the job
What is the server side language you have?
You need to set the below header from the server response,
Content-Disposition: attachment; filename=SasanKhan-Namoondi[320].mp3;
On the other hand, you can do the same at web server level. For an instance, if you use Apache, you can do this with .htaccess file
<IfModule mod_headers.c>
<FilesMatch "\.(mp3|MP3)$">
ForceType audio/mpeg
Header set Content-Disposition "attachment"
Allow from all
</FilesMatch>
</IfModule>
Also, you have to enable headers module to make this works,
Make sure the below is checked
Apache -> Apache Modules -> headers_module
Download
You can try this link:-How can I create download link in html?
Your code looks totally fine so it's certainly something with your browser or the download manager.
Have you tried it with another download manager?
Maybe you can give this one a try.
Related
Browsers (Chrome and Safari) Try to download this html file when opened. It is only on that link that it tries to download it. Also note that internet explorer opens it without a problem.
The one thing that I think is causing this may be wordpress or some plugin within wordpress but it seems unlikely since no wordpress is used in that page.
Contact html code
Likely an incorrect mime type in your .htaccess file. I suggest going into it and looking for any unwanted lines similar to the below and removing them.
AddHandler application/ etc.
and also ensure your type is set as follows:
AddType text/html .html
In order to open .htaccess in cPanel:
Click File Manager and make sure to tick Show Hidden Files (dotfiles) before clicking Go. Then the .htaccess should show up the location where wp (wp-admin, wp-content, wp-includes) is installed.
One possible cause is that there is a problem with your server configuration that is giving the visiting browser the wrong mime type.
The correct mime type for html is: text/html
The mime type that your server is sending is: application/x-httpd-php
You appear to be running Apache. As a result there are two possible files that could be causing this, either in .htaccess or in one of Apaches configuration files.
Try adding the text below to a .htaccess file in your directory, or look for a mention of application/x-httpd-php
AddType text/html .html
I had to add the following at it worked:
AddHandler application/x-httpd-php .php
I've had this issue a couple of times. The problem for me was the web server was automatically handling PHP requests outside of the .htaccess file. For some reason, changing settings in WordPress would sometimes cause a change in the .htaccess file, adding a handler for PHP. This would cause the server to burp at every PHP request thereafter and attempt to serve the file instead of handle it.
The solution, then, was to manually remove the handler that was automatically added to the .htaccess file (and leave a comment for myself so I wouldn't pull my hair out every time!)
Had same thing happen to me. I know this sounds funny but check to make sure none of the keys on your keyboard are stuck. i.e) ALT key , etc. if not. Try hooking up a new keyboard and then browse.
I want to create a single page such as this:
http://www.mywebsite.com/special/index.html
But anything in the /special/ folder should be able to load the index.html page. For example, if you go to
http://www.mywebsite.com/special/another-page.html
It should still load the index page but not change the URL in the browser or to search engines. Basically, you should be able to go to any page in the /special/ folder, keep the URL the same as you enter, but always load the index.html page. Any ideas?
A 404 or 301 redirect wouldn't work because that changes the URL in the browser and to search engines...
Thanks in advance!
A 404 redirect would not help, but a custom 404 handler would:
error404.php:
<?php
include('path/to/special/index.html');
?>
Assuming .html is a static or PHP page. If it is something else, youse the equivalent construct of that environment.
Using apache mapping it should be possible. I don't how to exactly do that but this doc http://httpd.apache.org/docs/2.0/urlmapping.html probably has the answer.
It is possible to use patterns to map URL to filesystem locations.
I think (untested) something like this would work in an .htaccess file in the special directory if you have the ability to use rewrite rules:
RewriteRule ^.*$ index.html
You would have to symlink index.html in the special directory to the real index.html.
The ^.*$ just means (beginning of line)(any amount of anything)(end of line) - basically a wildcard; there might be a better way of writing it.
Consider a webpage, located at http://www.example.com/mypage.html
Unfortunately, someone wrongly advertises that the page's address is http://www.example.com/mypage - people visiting that URL are seeing a 404.
How can I configure Apache so visitors to mypage end up at mypage.html ?
I tried "ln -s mypage.html mypage", but the raw HTML was displayed (I guess because the file was served as text/plain)
I guess I need something in a .htaccess page but I can't work out what...
I would rather redirect the user in stead of going the mime-type way:
Redirect 301 /mypage http://www.example.com/mypage.html
I've a link to a PDF file in my page.
Safari opens the pdf file directly in the website. I would like to download it instead.
I've tried to add target="_blank" to <a> element, but it doesn't work if the pop-ups are disabled in the browser settings.
How can I solve this?
thanks
To make so, you need to change headers for .PDF files.
So, in your .htaccess, you need to do like this:
AddType application/octet-stream .pdf
You need to set the Content-Disposition HTTP header to attachment for this file.
Content-Disposition: attachment; filename=test.pdf
Depending on the web server you are using the way to configure this might vary. Another option is to have a server side script which would stream the pdf and set this header.
You'll need to dynamicaly force attachement headers using a server side script like PHP.
Here's an example using PHP :
<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');
?>
Edit :
$file = $_GET['file'];
readfile($file."pdf"); // Before doing this, check whather the user have permission to download that file.
call your script : download.php?file=document
will download document.pdf
I have changed some file names on my web and now I want to make "301 Permanently Moved" redirect from the old files to the new ones.
The problem is that my web is made completelly by static html pages and all 301 redirect tutorials decribe how to do it in PHP, ASP, htaccess etc. I would like to write the redirect directly into the old html files, is this possible? Or do I have to contact my web provider and solve the redirect on the server?
The only thing I know about the server is that it runs on Windows and I have no server knowledge.
EDIT: My web hosting is using Microsoft IIS 7.0, so I assume using the .htaccess is not possible here?
EDIT #2: just now my server admin wrote me that even if I use only static HTML pages, I can still use web.config file to redirect individual html files. This is very nice.
You cannot alter the HTTP status code with HTML.
But if you’re using an Apache webserver, you could use mod_rewrite or mod_alias to redirect such requests to the new address:
# mod_rewrite
RewriteEngine on
RewriteRule ^old\.html$ /new.html [L,R=301]
# mod_alias
RedirectMatch 301 ^/old\.html$ /new.html
Edit As you now clarified that you’re using IIS 7, take a look at its <httpRedirect> element for HTTP redirects.
I guess you could use JavaScript and/or meta-refresh (as suggested by Gumbo) to redirect the users from your old pages to the new one.
Something like:
<html>
<head>
<meta http-equiv="refresh" content="0;url=http://YourServer/NewFile.html" />
<script type="text/javascript">
location.replace('http://YourServer/NewFile.html');
</script>
</head>
<body>
This page has moved. Click here for the new location
</body>
</html>
No, it isn't possible. HTML is not processed by the server, so it cannot set HTTP headers.
You should look at Apache configuration instead (e.g. with .htaccess).
At its simplist you could do:
Redirect 301 old.html http://example.com/new/
Redirect 301 other-old.html http://example.com/newer/
Redirecting individual pages in IIS is a simple affair and done in your web.config file.
<location path="products.htm">
<system.webServer>
<httpRedirect enabled="true" destination="http://yourserver/products" httpResponseStatus="Permanent" />
</system.webServer>
</location>