You cannot make this work work on the client side. Most importantly, you need to send the headers not as html. Therefore, I suggest you use server-side scripts, as Max suggested, and it is preferable to use the .htaccess file if you are using the Apache server to also name these files as .doc.
Suppose your php file has to create a .doc file with some argument passed, let's say id. So you want file_.doc to point to file.php? Id =, try using the following rewrite rule so that the browser also understands the RewriteRule file _ (. *) Extension. Doc file.php? Id = $ 1
source share