Why Won't Server Side Includes Work? - html

I have been trying to use Server Side Includes on my website to save time writing code and be able to change site wide elements quickly and easily.
However i cannot seem to get them to work, either locally or on the Server.
I have set them up as .html files (with only the code needed and no html or body tags) in a "ssi" folder and am calling them in the appropriate locations in my .shtml files with:
<!--#include virtual="/ssi/<filename>.html" -->
but still nothing. Any ideas?

Is it Apache? Perhaps includes are not even enabled.
http://httpd.apache.org/docs/2.2/howto/ssi.html
To permit SSI on your server, you must have the following directive either in your httpd.conf file, or in a .htaccess file:
Options +Includes

Have you enabled SSI on the Apache server?
You should have something like this in conf/http.conf:
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
This means that .shtml files are parsed for SSI commands (not .html) files. Then, you need to enable if fr your Virtual Host, or directory:
Options +Includes

It's possibly a path problem. Have you tried it without the leading "/" in front of "ssi"?

Related

How to fix website internal navigation/ Joomla

I have a situation to which I cannot seem to have a fix for !
The thing is I'm hosting a website on localhost (LAMP).
The website is created using Joomla Framework. The home page loads successfully when I navigate to the website on the localhost.
As soon as I click on any navigation links, a 404 error is displayed.
eg. homepage URL -
http://localhost/PortalSources/
Nav link -
http://localhost/PortalSources/tools/safety-assessment-tool.html
As soon as I manually add 'index.php' to the nav link
http://localhost/PortalSources/index.php/tools/safety-assessment-tool.html
the link starts to work and page loads successfully.
What could possibly cause this behavior ? How do I fix it so that I don't have to manually type in for every page on the website ?
You can probably find your answer here: https://docs.joomla.org/Enabling_Search_Engine_Friendly_(SEF)_URLs
Verify .htaccess is Enabled
Check that your Apache config file allows .htaccess overrides. You must make sure overrides are enabled or the .htaccess file in your Joomla! root directory will be ignored or cause an error. In the section of your virtual host configuration file or in the main (httpd.conf) configuration file you must have something similar to the example below enabling overrides:
<Directory "/home/user/public_html">
AllowOverride All
</Directory>
<Directory "/path/to/htdocs">
AllowOverride All Options=[an option],[an option],...
</Directory>
There are other ways to test if .htaccess is enabled if you do not have access to your site's configuration files. Please refer to the .htaccess tutorial found on The Apache Software Foundation website for additional information.
Step by Step
These are step-by-step instructions. Please follow them in the order they are presented here. If a step fails, do not continue until you have solved the problem.
Rename the file "htaccess.txt" in your Joomla!'s base folder to ".htaccess".
This step may not be necessary. Open .htaccess in a text editor. Uncomment RewriteBase / (remove the first character, #). If Joomla is installed in its own folder, the enter the Joomla folder name after the backslash. e.g. RewriteBase /yourjoomlafolder.
Log on to your Back-end and open the Global Configuration.
Enable the Use Apache mod_rewrite/URL rewriting option and Save. This option uses the Apache mod_rewrite function to eliminate the "index.php" portion of the URL.
Check if your site works correctly. Your URLs should now look like:
http://www.example.com/the-­news/1­-latest-­news/1-­welcome-­to­-joomla
If this option causes errors, please see How to check if mod rewrite is enabled on your server.
If it is not enabled and you have access to the file apache/conf/httpd.conf, open that file and check if the line LoadModule rewrite_module modules/mod_rewrite.so is uncommented. If necessary, uncomment the line and restart the Apache web server.
If mod_rewrite cannot be enabled, leave this option off. It does not matter if you leave the .htaccess file renamed.
If you think this necessary, enable Add suffix to URLs and Save. This option adds .html to the end of URLs. There are different opinions on whether this is necessary or even useful. Search engines do not seem to care if your URLs end in .html or not.
Open the Plugin Manager and enable the System - SEF plugin. This plugin adds SEF support to links in your Joomla articles. It operates directly on the HTML and does not require a special tag.

How to render pages without .html extension as html pages in Apache server

I made a webpage that should load a html files into a iframe. When you click something, it appears in . Although all of my files are html documents with html tags, they don't have extensions. So in the iframe, it renders as plain text. How do i configure Apache server setting so that the default file extension is set to ".html" when the file doesn't have any extension? Does it have anything to do with .htaccess file?
It seems like I can hide file extensions by doing some trick in that file, but I'm trying to do the opposite (adding an extension). How do I do this?
If you are using an old version of Apache:
DefaultType text/html
DefaultType Directive
MIME content-type that will be sent if the server cannot determine a type in any other way
For the current version:
Use the mime.types configuration file and the AddType to configure media type assignments via file extensions, or the ForceType directive to configure the media type for specific resources. Otherwise, the server will send the response without a Content-Type header field and the recipient may attempt to guess the media type.
So:
# force all files to be text/html:
<Location />
ForceType text/html
</Location>

How do I change the default index page in Apache?

I would like to change the default web page that shows up when I browse my site. I currently have a reporting program running, and it outputs a file called index.html. I cannot change what it calls the file. Therefore, my landing page must be called something else. Right now, when I browse my site it takes me to the reporting page.
From what I see, whatever you call index.html it will pull that up as your default. I want to change that to landing.html. How do I do this?
I am a folder (Folding # Home). The reporting program is HFM.net. HFM can output an html file with my current folding statistics. It names the html file index. I do not want that to be my default home page. I would like a menu-like landing where I can choose if I want to see my stats, or something else. The website is at /home/tyler/Documents/hfm/website (landing.html and hfm's index.html are here). Apache2 is in its default directory.
I'm also running Ubuntu 13.04.
I recommend using .htaccess. You only need to add:
DirectoryIndex home.php
or whatever page name you want to have for it.
EDIT: basic htaccess tutorial.
1) Create .htaccess file in the directory where you want to change the index file.
no extension
. in front, to ensure it is a "hidden" file
Enter the line above in there. There will likely be many, many other things you will add to this (AddTypes for webfonts / media files, caching for headers, gzip declaration for compression, etc.), but that one line declares your new "home" page.
2) Set server to allow reading of .htaccess files (may only be needed on your localhost, if your hosting servce defaults to allow it as most do)
Assuming you have access, go to your server's enabled site location. I run a Debian server for development, and the default site setup is at /etc/apache2/sites-available/default for Debian / Ubuntu. Not sure what server you run, but just search for "sites-available" and go into the "default" document. In there you will see an entry for Directory. Modify it to look like this:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Then restart your apache server. Again, not sure about your server, but the command on Debian / Ubuntu is:
sudo service apache2 restart
Technically you only need to reload, but I restart just because I feel safer with a full refresh like that.
Once that is done, your site should be reading from your .htaccess file, and you should have a new default home page! A side note, if you have a sub-directory that runs a site (like an admin section or something) and you want to have a different "home page" for that directory, you can just plop another .htaccess file in that sub-site's root and it will overwrite the declaration in the parent.
You can also set DirectoryIndex in apache's httpd.conf file.
CentOS keeps this file in /etc/httpd/conf/httpd.conf
Debian: /etc/apache2/apache2.conf
Open the file in your text editor and find the line starting with DirectoryIndex
To load landing.html as a default (but index.html if that's not found) change this line to read:
DirectoryIndex landing.html index.html
I had a similar problem. When providing http://server/appDirectory I got a directory listing instead of index.html even though I had
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
in my httpd.conf file.
My solution was to uncomment the
LoadModule setenvif_module modules/mod_setenvif.so
line in httpd.conf
Apache version: 2.4
In Ubuntu you can add in file:
/etc/apache2/mods-enabled/dir.conf
line
DirectoryIndex myhomepage.htm
and then restart apache service
sudo systemctl restart apache2
In Unbuntu, you can update the default page on a site-by-site basis with the site config files eg:
/etc/apache2/sites-available/your.domain.conf
Same syntax for the key line in the file, eg mine is;
DirectoryIndex default.htm index.htm
Then don't forget to enable and reload:
sudo a2ensite your.domain.conf
sudo systemctl reload apache2

Application Cache html5

I'm learning how application cache works, but I got a problem.
I created my manifest file and 'imported' it in my index.html.
In the offline.manifest file I added:
CACHE MANIFEST
34567.js
and in my index file:
<html manifest="offline.manifest">
I'm working on localhost, but when I tried to search the script, I get nothing.
I erased the cache too, but result is the same.
I read about creating an .htaccess file and I created it with this string:
AddType text/cache-manifest .manifest
But, where I'd put it?
Apache's .htaccess file, which configures the web server, can be placed anywhere in the directory tree so long as you write your directive paths correctly. Based on the syntax AddType text/cache-manifest .manifest you'd need to keep the .htaccess in the same directory as the .manifest file here.
See this very similar question via the StackExchange network.
If you are not serving the .manifest with the correct text/cache-manifest content type it will be ignored.

HTML5: Why I need to add manifest file to .htaccess?

I have seen some articles about HTML5 Manifest, which say that we must add manifest file to .htaccess with following line:
AddType text/cache-manifest .manifest
However, there is no any explnation what is the purpose of adding?
Where should I place this .htaccess file ? in the same folder where the manifest file is? and finally how can i make sure that it is added to .htaccess successfully?
Even if i do not create any .htaccess file, i only add this to my html file
<html manifest="site.manifest">
I can see the popup bar in firefox, asking that the website is asking to store data. So isn't it working without this .htaccess?
I'll appriciate if anyone can explain. Thanks.
You don't "add a manifest file" to .htaccess with that line. That line just tells Apache that files with the suffix ".manifest" will be of type text/cache-manifest. Apache tells the client about the file type in the HTTP content-type header. The HTTP content-type header is required for the browser/client to understand how to interpret the contents of the file. Refer:
AddType Directive # httpd.apache.org
The cache manifest in HTML5 # en.wikipedia.org
The cache manifest syntax # w3.org
Offline Web Applications # w3.org