View Single Post
Old 03-24-2013, 07:22 PM  
robber
Web Developer
 
Industry Role:
Join Date: Jan 2011
Location: UK
Posts: 264
Quote:
Originally Posted by redmark View Post
What most webmasters do to include html code to their pages like a menu on top of every pages of the site that can be updated without manually change all these pages.

What is the right way to do this for seo, server speed and user friendly

I need step by step details for server configuration
Thanks in advance
Showing Pages as .htm

Ok you have two methods, you could use .htaccess to map all the .php files to be .htm, but this involves using a reasonable structure as the rules can be fiddly if you have a lot of subdirectories of different depths that you need to display content from.

or as previously suggested get the server to parse all .html / .htm files as php. This is something which can backfire if you're not careful as it will evaluate all .html / .htm files, which could slow the server down if it's only a handful which need to be php.

Showing standard menu across top of site

You can either create a standard template and have that used across the site, then you only need to update the template (this involves some forward planning, but can be good if you what to have a dynamic site).

Or you can include the menu on all the pages you need (same with the footer info), to do this you can write it as

Code:
<?php
   @include_once("menu.php"); # For your menu
   @include_once("footer.php"); # For your footer
   # ..... you can carry this on for as many elements you want.
?>
What I do

Personally I would create one template and then link all the pages up and feed them in through $_GET[] in the url's and it would have the page names being mapped by a .htaccess file using mod_rewrite functions. It might sound a little complicated to start with but it will pay off if you're creating a site which needs to be able to grow and expand quickly without the need to create every single page, take for example http://livegfcam.com this creates all the pages and links you see dynamically, all I have done is write the template, directory mapping and layout, if you looked at the server there are only a handful of files and the directories you see in the URL do not exist.

I use this solution as I know php well enough to be able to create a lot of my content on the fly, what I would suggest is to think about what you want to do, google the question then if you can't understand the answer either post on the forums or if you don't want to do that, you can always drop me an email rob [at] foxydrop [dot] com

An example from a project I'm currently doing (edited down to remove some of my features so you can get an idea)

Example

index.php

Code:
<?php

ob_start();

## FTGP V 2.0 :D ##

@require_once("config.php");
$url = str_replace("www.","",$_SERVER["HTTP_HOST"]);

$sq = @mysql_query("select * from sites where address='".$url."' limit 0,1");
$tgps = @mysql_fetch_assoc($sq);

$sitename = $tgps['title'];

?><html>
<head>
<title><?php echo $sitename; ?></title>
<link href="/style.css" rel="stylesheet">
</head>
<body>
<img src="/title/<?php echo $tgps['title']; ?>.jpg" alt="<?php echo $sitename; ?>">
<div id="wrapper">
<?php
	if($_GET['page']== "index" || empty($_GET['page'])) $_GET['page'] = "home";
	if(file_exists($_GET['page'].".php")){
		include_once($_GET['page'].".php");
	} else {
		include_once("home.php");
	}
?>
<div style="clear:both"></div>
</div>
<div id="foot">
	<!-- Footer info here -->
</div>
<span style="clear:both">&nbsp;</span>
</body>
</html><?php

ob_end_flush(); ?>
.htaccess

Code:
#start .htaccess code
## FTGP 2 by FoxyDrop.com ##

RewriteEngine On
RewriteBase /

####### Security #######

<FilesMatch ?\.(htaccess|htpasswd|ini|pg|eps|log|sh)$?>
Deny from all
</FilesMatch>

## Lock Directories ##

Options -Indexes -MultiViews +FollowSymlinks

## Hotlink Protection

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?(top\.)?foxydrop.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

####### House Keeping #######

## Error Pages ##

ErrorDocument 401 /?pg=404&error=401
ErrorDocument 403 /?pg=404&error=403
ErrorDocument 404 /?pg=404&error=404
ErrorDocument 500 /?pg=404&error=500

####### Clean URLS #######

## General ##

RewriteRule ^([^/\.]+).htm?$ index.php?page=$1 [L]
RewriteRule ^sitemap.xml?$ sitemap.php [L]
The above are simple examples the actual files are much more indepth as I have multisite templates which span across a wide number of sites. I've removed a lot of the .htaccess file and parts of the template as they are all the extras like my actual footer and all my tracking and ad details, as well as the additional network sites.

Also just to point out the actual working parts of the site like the actual pages which are being included are the ones which have most of the code in this is just the template part of the site.

Hope this helps

Rob
robber is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook