Showing posts with label SEO Optimization. Show all posts
Showing posts with label SEO Optimization. Show all posts

Thursday, March 7, 2013

Fix External Broken links PHP

Adding External links may not guarantee to available all time, following code will check header response before redirect the user to that particular url using the following Code.


$url = "";

$user_agent = 
'Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0'

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);

// Then, after your curl_exec call:
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);

echo "<pre>";

// Re
HTTP/1.1 200 OK
Server: Apache/2.2.3 (Red Hat)
Last-Modified: Tue, 03 Jul 2012 15:28:22 GMT
ETag: "bc241f05-1aace1-4c3ee90929180"
Accept-Ranges: bytes
Content-Length: 1748193
Content-Type: application/pdf
Date: Thu, 07 Mar 2013 11:36:42 GMT
Connection: keep-alive


Checking corresponding Content-Type before redirecting user help to improve user experience.

Thursday, May 31, 2012

htaccess redirect with or without www

Developing SEO friendly website, you have to decide the domain name is whether it is with "WWW" or without "WWW". as per your need you can transform the user behavior by redirecting reversal order based on your need. If you decide without WWW mean, while user attempt to type with you need to redirect, If you decide with WWW mean, you need to redirect with www when user typing to

In this case, We have the great option in .htaccess to decide with or without WWW .
Here is the solutions for htaccess redirect with or without www

Examples with mentioning Domain Name

Redirect WWW to non-WWW or without WWW Domain Name:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Redirect non-WWW to with WWW Domain Name:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ [NC]
Rewriterule ^(.*)$$1 [R=301,NC]

Example with Suitable for any Website without mentioning the domain name:
(Suitable for any Website) no need to tell the domain name on code.

Redirect www to non-www (both: http + https)
if we need to do this for separate http and https:

Options +FollowSymLinks
RewriteEngine On

# if without https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# if https
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Redirect non-www to www (both: http + https)
if we need to do this for separate http and https:

Options +FollowSymLinks
RewriteEngine On

# if without https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# if https
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

Tuesday, March 6, 2012

How to SEO Website, Series.

Search Engine Optimization SEO, is an key work for any website to promote your business or brand through web among Search Engines. Here is the Major points as a answer for your question, We will saw one by one in this "How to SEO Website" Series.

How to SEO your Website

12. Optimize Title
11. Local Listing
10. Sitemap Submission
09. Blogger Linking
08. Sidelink Showing
07. Google Trends
06. Social Singles
05. Followed Links
04. 404 Fixes
03. 301 Fixes
02. Indented Listings
01. You will get first Place on Google

Sunday, March 4, 2012

Remove HTML comments PHP

Cleaning or Removing HTML comments is one of the main part of Optimizing web pages. Here is the solution to Remove HTML Comments with PHP.

To Remove HTML Comments in PHP, We need to use the following Technique.

Remove HTML Comments with PHP
// Start OutputBuffer
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Remove HTML Comments</title>

<!-- // HTML Comments for code identification -->

<!-- Mutiple Closing Tags-->
<h1>Remove HTML Comments Example</h1>
<!-- Unclose End Tag-->
<p>This is an example to remove HTML Comments <p>

// Store HTML Output Buffer as variable with ob_get_clean();
$html = ob_get_clean();

// Specify configuration
$config = array(
           'indent'         => false,
     'hide-comments' => true,
           'output-xhtml'   => true,
           'wrap'           => false

// Tidy
$tidy = new tidy;
$tidy->parseString($html, $config, 'utf8');

// Output
echo $tidy;

Friday, March 2, 2012

PHP Tidy - Clean HTML Tags, HTML code, HTML Source, Comments

Website Webpage Optimization part, HTML pages contain many unnecessary development usage section such as Comments, Indents, Empty Lines, Accidental Enclosed tags without End Tag, Unknown Closing Tag, These are very sensitive for Browser Compatibly Issues, Page Loading Time and Web Page Optimization

We can able to keep our Web pages keep away from Unnecessary things such Comments, Un closed Tags, Un closed End Tags using HTML Tidy Object from PHP.

Here is the Example Code for PHP tidy Object. with Examples.
With this Example We have to use tidy Object (Tidy Object need to Enabled in PHP Configuration).
Check with phpinfo() under Tidy. ob_get_clean() , parse HTML String with parseString() function from Tidy object, and Clean our HTML with cleanRepair()

Saturday, February 25, 2012

Reduce HTTP Request with Data URI in PHP

A part of website optimization technique is Reduce no of HTTP Request when user attempt to open our Web page from our website. HTTP Request count is an important factor for Traffic worthy websites to make your web pages / websites more responsive on time. In this factor of HTTP Request optimization to reduce the HTTP request count of various images in our websites by Rewriting with Data URI Scheme. Data URI is the technology which is used to Reduce and Optimize HTTP request and response.

For example If you have a gallery section in your website. Gallery images are in two Sections one is Thumbnails and another one is actual images. in this case set of 5 Images will request 10 HTTP request every time the Page opens. in this case we can use Data URI with PHP to reduce this HTTP request 0, Data URI will cheat our server and retrieve the image data as plain code along with our standard HTML code.

Wednesday, February 22, 2012

Directory Model URL Rewriting with htaccess and map content with php

Creating a dynamic content for web application, we need to consider the Search Engine Optimized web URL structure to main the quality of our web development says "SEO Friendly", Search Engines are clearly identified our web content if we have Directory Model URL structure in our websites. As a developer SEO Friendly URL is very important to any project. Let me explain How to create Directory Model URL Rewriting with htaccess and how to map your content with php.

.htaccess directory structure url rewriting

directory structure: