Insert HTML code in all pages via Apache?

前端 未结 3 1164
青春惊慌失措
青春惊慌失措 2021-01-13 03:17

I don\'t know if Apache or .htaccess is the right way, but I like to know how to insert an HTML code to all pages inside a public_html directory, k

相关标签:
3条回答
  • i can insert html to all pages via Apache, but only for site that hosted by my apache, not all site though my apache proxy server.

    this is how it work. i set up an XAMPP, download mod_layout 5.1 for apache 2.4. (install mod_layout is simple, if you use XAMPP for windows, just download mod_layout.so 5.1 for windows and put it to your apache module folder $home/apache/module, then add the config DSO to your httpd.conf LoadModule layout_module modules/mod_layout.so - if you using linux or other os, you should download mod_layout.so for linux, then run make command to install)

    After install mod_layout.so for windows, just put this code on your .htaccess file or httpd.conf your will get html insert to all your page:

    <IfModule mod_layout.c>
    AddOutputFilter LAYOUT html 
    AddOutputFilter LAYOUT htm 
    AddOutputFilter LAYOUT shtml 
    AddOutputFilter LAYOUT shtm 
    AddOutputFilter LAYOUT cgi 
    AddOutputFilter LAYOUT php 
    LayoutFooter "C:/xampp/apache/cgi-bin/footer.php"
    </IfModule>
    

    C:/xampp/apache/cgi-bin/footer.php is where you put your html or php file, in my situation is C:/xampp/apache/cgi-bin/footer.php, but you can put it any where, just give the right path, you'll be fine

    0 讨论(0)
  • 2021-01-13 03:48

    You can use the following method to insert HTML code to all pages within a specific directory using .htaccess:

    <Directory "/public_html/">
        # Prepend to top
        php_value auto_prepend_file "/dir/path/banner.php"
    
        # Append to bottom
        php_value auto_append_file "/dir/path/footer.php"
    </Directory>
    

    The following article discusses how .htaccess can allow you to prepend/append html to every page request:

    http://davidwalsh.name/prepend-append-files-htaccess

    The following article discusses how to use the .htaccess directory block:

    htaccess <Directory> deny from all

    0 讨论(0)
  • 2021-01-13 03:48

    You can do this by creating a custom output filter using ExtFilterDefine and SetOutputFilter and have that run a PHP script which reads stdin:// then inserts the code you want and outputs it. Check out http://httpd.apache.org/docs/2.2/mod/mod_ext_filter.html to get started.

    If you're just concerned with PHP output and not static HTML files as well, you could use auto_prepend_file to run a script which calls ob_start(), and auto_append_file to run a script which calls $html = ob_get_clean() and inserts the code into $html before echoing it out.

    0 讨论(0)
提交回复
热议问题