Mobile app version of vmapp.org
Login or Join
Barnes591

: Apache htaccess results in files being downloaded instead of displayed So I had this "beautiful" website that did exactly what I wanted it to do. Then I shut down my PC, reboot and...the pages

@Barnes591

Posted in: #Apache #Htaccess #ModRewrite #Xampp

So I had this "beautiful" website that did exactly what I wanted it to do. Then I shut down my PC, reboot and...the pages just download now instead of being displayed.

I re-installed XAMPP and launched Apache again and I was able to identify the .htaccess file as the cause of the problem.

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{QUERY_STRING} !^desktop
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|iphone|ipod #opera mobile|palmos|webos" [NC]
RewriteRule ^/?$ /mobile/index [L,R=302]
RewriteRule ^/?$ /de/index [R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ .html


Here is the problem I guess:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ .html


This should make it possible to use /de/index instead of /de/index.html - but somehow it causes the page to download if I open localhost/de/index (but with localhost/de/index.html it works fine...).

I'm using HTML Sites with SSI Elements on a Apache web server. The only other file that is different to the out-of-the-box ones is the httpd.conf, where I enabled SSI:

AddType text/html .shtml
AddHandler server-parsed .shtml
AddHandler server-parsed .html
AddHandler server-parsed .htm
Options Indexes FollowSymLinks Includes
AddOutputFilter INCLUDES .shtml
Options +Includes


So I hope there is somebody among you that can help me with this annoying problem as I'm quite desperate... for some reason, even without the problematic lines Chrome keeps downloading the files (even if I delete the .htaccess file), while IE and Opera display the pages.

Edit: Now Opera also wants to download files (whether index.html or index are called).

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

1 Comments

Sorted by latest first Latest Oldest Best

 

@Megan663

Browsers offer to download files based on two headers:


Content-Type
Content-Disposition


I use a command line tool called curl to check headers on a website.

curl -s -D - 'http://example.com/' | head -n 20


If you don't want your pages to be downloaded, then the Content-Type should be set to text/html or text/html;charset=UTF-8 and there should be no Content-Disposition header.

Browsers will offer to save pages as a download if the Content-Type header is something like application/octet-stream. A download dialog box will also be presented if there is a Content-Disposition header such as attachment; filename=foo.html.

You can generally control the Content-Type through .htaccess using the AddType directive like such:

AddType text/html .html


I see that you are already doing this for .shtml files. You may have to do the same for other extensions such as .html and .htm.

This is then the default type for files with those extensions, but if they are backed by a web application, the code that runs that web application usually has the ability to override them. Most web application frameworks have some sort of setHeader directive that can be used to set both Content-Type and Content-Disposition. In addition to checking your .htaccess file, you will need to check the code that powers your website.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme