Server Side Includes?

Connect with other users about what to run on your webhosting (and how to run it) here.
Post Reply
User avatar
SG-17
New to forums
New to forums
Posts: 11
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Fri Mar 01, 2024 6:07 am
Contact:

Server Side Includes?

Post by SG-17 »

I'm trying to setup server side includes on my site to standardize my header and footer without using jQuery and it doesn't seem to be working.
I've added the correct configs to .htaccess but even then its a no-go. Is mod_include not enabled in the version of Apache that NFO uses?

https://httpd.apache.org/docs/2.4/howto/ssi.html
User avatar
Edge100x
Founder
Founder
Posts: 13071
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Server Side Includes?

Post by Edge100x »

I haven't had anyone ask about those before, but they should work. you'd have to use AddType, AddOutputFilter, and set the options on the folder properly. What does your .htaccess look like?
User avatar
SG-17
New to forums
New to forums
Posts: 11
Joined: Fri Mar 01, 2024 6:07 am
Contact:

Re: Server Side Includes?

Post by SG-17 »

Edge100x wrote: Sat Mar 01, 2025 12:44 pm I haven't had anyone ask about those before, but they should work. you'd have to use AddType, AddOutputFilter, and set the options on the folder properly. What does your .htaccess look like?

Code: Select all

ErrorDocument 404 /404.html
Options +Includes -Indexes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
RewriteEngine On

RewriteBase /
#terminate all rewrite loops
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
#1)Remove ".html" , ".php",".css" extension.
#The following rule redirects "/file.ext" to "/file" 
RewriteRule ^(.+)\.(html|php|css)$ $1 [L,R,NE]
#checks if "/file" .html exists, if it exits ,map "/file" to "/file.html"
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [L]
#checks if "/file" .php exists, if it exits ,map "/file" to "/file.php"
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
#checks if "/file" .css exists, if it exits ,map "/file" to "/file.css"
RewriteCond %{REQUEST_FILENAME}.css -f
RewriteRule ^(.*?)/?$ $1.css [L]
On my test page I have

Code: Select all

<!--#include file="/header.shtml" -->
<!--#include file="/footer.shtml" -->
in their respective places on the page.
User avatar
SG-17
New to forums
New to forums
Posts: 11
Joined: Fri Mar 01, 2024 6:07 am
Contact:

Re: Server Side Includes?

Post by SG-17 »

I think I figured it out, I needed to add .html and .php to the AddOutputFilters

So now its

Code: Select all

AddOutputFilter INCLUDES .shtml .html .php
and it seems to be working.
User avatar
Edge100x
Founder
Founder
Posts: 13071
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Server Side Includes?

Post by Edge100x »

If you want .html and .php files to be parsed, you would, yes. That's not the standard configuration and it will slow things down, so it's not recommended. It is usually better to use XBitHack and set +x on the .html files, per the documentation. You shouldn't have .php files in the list; with PHP, you just use scripting to handle this, instead.
User avatar
SG-17
New to forums
New to forums
Posts: 11
Joined: Fri Mar 01, 2024 6:07 am
Contact:

Re: Server Side Includes?

Post by SG-17 »

Edge100x wrote: Sat Mar 01, 2025 7:21 pm If you want .html and .php files to be parsed, you would, yes. That's not the standard configuration and it will slow things down, so it's not recommended. It is usually better to use XBitHack and set +x on the .html files, per the documentation. You shouldn't have .php files in the list; with PHP, you just use scripting to handle this, instead.
Is there a way to chmod all of the html pages in my site at once?

I went and removed .php and added php includes for each of them.
User avatar
Edge100x
Founder
Founder
Posts: 13071
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Server Side Includes?

Post by Edge100x »

Yes, you could use the "find" command from a shell to do that sort of thing. A command like this, for instance:

Code: Select all

find /usr/www/youridentifier/the/directory/tree/to/change/in -name "*.html" -execdir chmod +x {} \;
(There are other ways, including using xargs, that may be more efficient, but -execdir is simplest.)
User avatar
SG-17
New to forums
New to forums
Posts: 11
Joined: Fri Mar 01, 2024 6:07 am
Contact:

Re: Server Side Includes?

Post by SG-17 »

Edge100x wrote: Sat Mar 01, 2025 10:22 pm Yes, you could use the "find" command from a shell to do that sort of thing. A command like this, for instance:

Code: Select all

find /usr/www/youridentifier/the/directory/tree/to/change/in -name "*.html" -execdir chmod +x {} \;
(There are other ways, including using xargs, that may be more efficient, but -execdir is simplest.)
Thanks, that worked. Now if I create new pages will I need to set the +x again for them?

Is there any downside to just making any new pages .php and using .php includes going forward even if thats the only php on the page?
User avatar
SG-17
New to forums
New to forums
Posts: 11
Joined: Fri Mar 01, 2024 6:07 am
Contact:

Re: Server Side Includes?

Post by SG-17 »

Oh wait, can I just set the file permissions in FileZilla, checking the Execute box for new pages?
User avatar
Edge100x
Founder
Founder
Posts: 13071
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Server Side Includes?

Post by Edge100x »

That would likely work, yes.

No real downsides to using PHP either, no.
User avatar
SG-17
New to forums
New to forums
Posts: 11
Joined: Fri Mar 01, 2024 6:07 am
Contact:

Re: Server Side Includes?

Post by SG-17 »

Thanks for your help. Sometimes the documentation can be a bit obtuse for amateurs like myself.
Post Reply