Server Side Includes?
- SG-17
- New to forums
- Posts: 11
- https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
- Joined: Fri Mar 01, 2024 6:07 am
- Contact:
Server Side Includes?
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
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
Re: Server Side Includes?
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?
Re: Server Side Includes?
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]
Code: Select all
<!--#include file="/header.shtml" -->
<!--#include file="/footer.shtml" -->
Re: Server Side Includes?
I think I figured it out, I needed to add .html and .php to the AddOutputFilters
So now its
and it seems to be working.
So now its
Code: Select all
AddOutputFilter INCLUDES .shtml .html .php
Re: Server Side Includes?
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.
Re: Server Side Includes?
Is there a way to chmod all of the html pages in my site at once?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.
I went and removed .php and added php includes for each of them.
Re: Server Side Includes?
Yes, you could use the "find" command from a shell to do that sort of thing. A command like this, for instance:
(There are other ways, including using xargs, that may be more efficient, but -execdir is simplest.)
Code: Select all
find /usr/www/youridentifier/the/directory/tree/to/change/in -name "*.html" -execdir chmod +x {} \;
Re: Server Side Includes?
Thanks, that worked. Now if I create new pages will I need to set the +x again for them?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:
(There are other ways, including using xargs, that may be more efficient, but -execdir is simplest.)Code: Select all
find /usr/www/youridentifier/the/directory/tree/to/change/in -name "*.html" -execdir chmod +x {} \;
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?
Re: Server Side Includes?
Oh wait, can I just set the file permissions in FileZilla, checking the Execute box for new pages?
Re: Server Side Includes?
That would likely work, yes.
No real downsides to using PHP either, no.
No real downsides to using PHP either, no.
Re: Server Side Includes?
Thanks for your help. Sometimes the documentation can be a bit obtuse for amateurs like myself.