#include virtual in .html file - cgi

I'm moving over a site that is built on CGI. I have all the .cgi pages working properly, but a couple .html files contain <!--#include virtual="show_testimonials.cgi" --> but won't output the script within the html file.
Do I need to add something specifically to my .htaccess file to get Server Side Includes to work?

try to rename to .shtml or check your apache config. There you can also specify the SSI handler to parse .html files.

AddHandler server-parsed html
in your .htaccess file will cause all your .html files to be parsed by the server.

Related

Why can't I upload .htaccess file using terminal?

I have a Amazon EC2 server running Apache, I'm trying to enable SSI using .htaccess file, I created the .htaccess file and saved it to my website files folder (not my server), and tried to upload it using scp -i /Users/jeffArries/Desktop/jeffarries.pem /Users/jeffArries/Desktop/Website_Testing_Folder/.htaccess ec2-user#ec2-54-213-219-247.us-west-2.compute.amazonaws.com:/var/www/html in Terminal, and got this error message:
"/Users/jeffArries/Desktop/Website_Testing_Folder/.htaccess: No such file or directory"
How can I upload my .htaccess file to my Apache server using Terminal?
Thanks!
Update:
Update 2:
As can be seen in the output of ls -Abl, the filename is actually .htaccess.txt.
Side note:
Enabling SSI for every .html file is a bad idea performance-wise. THe typical way is to use a special extension (like .shtml), or execute bits on the file (via XBitHack).
On Apache 2.4, the current way is to enable the INCLUDES filter instead of using AddHandler:
AddType text/html .html
AddOutputFilter INCLUDES .html
…
AddHandler server-parsed is still supported for backward compatibility.

FilesMatch or Files for Single File HTACCESS

My site has subdirectories that include index.html files.
www.domain.com/.htaccess
www.domain.com/index.html
www.domain.com/otherstuff/index.html
I have the following in the .htaccess file to run some php code on my main index page, but I know it also affects the index.html files in my subdirectories. How do I write it so it applies only to www.domain.com/index.html?
<Files index.html>
AddHandler x-httpd-php5-cgi .html
</Files>
I found this:
Precise targeting of the Filesmatch directive
But I'm not interested in using an alternative method like redirecting because it doesn't answer the question. I want to know if it's possible to do it this way and if it is, how? If it's not actually possible, then I'll know that for future reference and will always use an alternative.
Thanks!
See the RemoveHandler docs:
The RemoveHandler directive removes any handler associations for files with the given extensions. This allows .htaccess files in subdirectories to undo any associations inherited from parent directories or the server config files.
So in the "otherstuff" directory, add another htaccess file that says:
<Files index.html>
RemoveHandler .html
</Files>

Excluding one directory in .htaccess (not just rewrite rules)

Excluding one or more directories from rewrite rules in .htaccess files seems to be a common question. However, my .htaccess does more than just set rewrite rules. I've also set some server changes (we don't have suPHP on this server) as well as set some prepending of some php files. For example these are a few examples:
# Make files ending in .php, .html and .xml files etc. parsed by php.
AddType application/x-httpd-php .php .html .xml .css .js .le .txt
<FilesMatch "\.html$">
php_value auto_prepend_file "/home/2427/spwebsites/www.spwebsites.co.uk/incs/phps/config.php"
</FilesMatch>
# Internal Server Error
ErrorDocument 500 /admin/errors.html?code=500
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-]+)/$ $1.html [L]
I don't want any of these set for one directory (where my word press installation is), is there a way I can do this? Can I set a conditional statement for the whole .htaccess file?
Adding a blank .htaccess file in the word press directory won't work because this won't undo the settings in the parent directory.
I was just looking into your dilemma and it is a tricky one. It would be nice to be able to have the DirectoryMatch directive available in .htaccess ...
What you can try is to reset your values in the specific directory via another .htaccess file.
So in the case of the AddType perhaps, resetting it back to just ".php" might work (assuming it doesn't inherit the other values). Definitely not an ideal solution with out access to the main config file/ virtual host.
Here is a weird idea that you can try/test ... place the "wordpress" dir outside of the main root (or whereever you have the offending .htaccess file). Now route all requests to the wordpress (inner dir) to the outer dir. I wonder if Apache would not use the offending .htaccess considering the requests are being routed?

Allow SSI include directive for all HTML pages in htdocs folder using MAMP

I use MAMP to develop sites. I have each site in it's own folder in the htdocs folder. I manage one site that I need to use ssi directives on, because the host doesn't allow php includes.
I've un-commented these lines in httpd.conf file:
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
I added a .htaccess file in the htdocs folder with the following:
AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
On the site index page the include works using:
<!--#include file="top-nav.shtml" -->
But it does not work on files in any sub folder. I get this error:
[an error occurred while processing this directive]
I find the most common reason that SSI still fails following these set up procedures is that that the port (default 8888) is not specified when calling the local web page in the browser.
See: http://documentation.mamp.info/en/mamp/first-steps
It turns out that that using virtual rather than file works on sub directories. I'm still not sure if there is any particular reason file doesn't work. The question was answered on serverfault.com.
The thread is available here: https://serverfault.com/questions/214096/how-to-enable-ssi-for-all-html-files

How to make htaccess set file type on a particular file?

So what I need to do is make it so a html file (without the html extension) gets viewed as an html file.
I had this line:
AddType application/msword mypage
but apparently that last argument in .htaccess only supports extensions. Is there a way to have that thing work on a particular file?
<Files nosuffix>
DefaultType text/html
</Files>
References: DefaultType and Files.