Make header and footer files to be included in multiple html pages

前端 未结 11 2035
無奈伤痛
無奈伤痛 2020-11-22 06:49

I want to create common header and footer pages that are included on several html pages.

I\'d like to use javascript. Is there a way to do this using only html and

11条回答
  •  天涯浪人
    2020-11-22 07:36

    Must you use html file structure with JavaScript? Have you considered using PHP instead so that you can use simple PHP include object?

    If you convert the file names of your .html pages to .php - then at the top of each of your .php pages you can use one line of code to include the content from your header.php

    
    

    Do the same in the footer of each page to include the content from your footer.php file

    
    

    No JavaScript / Jquery or additional included files required.

    NB You could also convert your .html files to .php files using the following in your .htaccess file

    # re-write html to php
    RewriteRule ^(.*)\.html$ $1.php [L]
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
    
    
    # re-write no extension to .php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    

提交回复
热议问题