PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: htaccess
htaccess - phponwebsites.com
Showing posts with label htaccess. Show all posts

18 Apr 2015

Create Search API like itunes Search API using PHP and MySQL

                      The Apple itunes provided a search API for retrieve app information from it. The Apple search API display result as JSON format. Do you want to know more information about Apple itunes search API, then visit iTunes Search API.

                      You can also create search API like Apple itunes search API if you know how to create JSON file using PHP. Due to this, you can provide search API for your websites. If you didn't know create JSON file using PHP and MySQL, then visit How to get output as JSON format using PHP and Mysql.

Generate Search API using PHP and MySQL


                       Lets see how to create search API using PHP.  Follow below steps to generate search API for your websites using PHP.

Step1: Connect MySQL database using PHP


                     Connect your MySQL database to get stored values from it using PHP. The PHP code for connect MySQL database is below:

 mysql_connect('localhost','root','') or die(mysql_error());
 mysql_select_db('fitness') or die(mysql_error());


Step2: Get value from url using PHP


                     While user search something on your search API, you need to get those values for search from url. So only you can provide particular results from your MySQL database. This is done by below PHP code.

 $field=$_REQUEST['field'];
 $limit=$_REQUEST['limit'];

Step3: Make MySQL select query


                     After got values from url, you've to make MySQL query to select corresponding results from database. You can get zero or more than one values from urls for search. You should make MySQL query like below using PHP.

 if($field!='' && $limit!='')
 {
   $cond="where name='".$field."' order by id desc limit 0, $limit";
 }
 if($field=='' && $limit!='')
 {
   $cond="order by id desc limit 0, $limit";
 }
 if($field!='' && $limit=='')
 {
   $cond="where name='".$field."' order by id desc limit 0, 50";
 }
 if($field=='' && $limit=='')
 {
   $cond="order by id desc limit 0, 50";
 }
 $q=mysql_query("select * from f_img $cond") or die(mysql_error());

Step4: Add header for get output as JSON format


              You must add header type ato your PHP script for get output as JSON format. This is like below

 header('Content-Type: Application/json');

Step5: Add content to JSON file using PHP


               You need to create 2 array for create output as multidimensional array. Retrieve values from query result using mysql_fetch_arrayThen you push values to array using array_push() in PHP. Finally encode the results to display output as JSON format using json_encode().

               The full PHP code for create search API is represented below,


<?php
 error_reporting('E_ALL ^ E_NOTICE');
 mysql_connect('localhost','root','') or die(mysql_error());
 mysql_select_db('fitness') or die(mysql_error());
 $field=$_REQUEST['field'];
 $limit=$_REQUEST['limit'];
 if($field!='' && $limit!='')
 {
   $cond="where name='".$field."' order by id desc limit 0, $limit";
 }
 if($field=='' && $limit!='')
 {
   $cond="order by id desc limit 0, $limit";
 }
 if($field!='' && $limit=='')
 {
   $cond="where name='".$field."' order by id desc limit 0, 50";
 }
 if($field=='' && $limit=='')
 {
   $cond="order by id desc limit 0, 50";
 }
 $q=mysql_query("select * from user $cond") or die(mysql_error());
 header('Content-Type: Application/json');
 $details=array();
 $user=array();
 while($res=mysql_fetch_array($q))
 {
  $user['name']=$res['name'];
  $user['state']=$res['state'];
  $user['country']=$res['country'];
  array_push($details,$user);
 }
 //print_R($details);
 echo json_encode($details);

?>


           Your JSON output should be like below,


[
 {"name":"Clark","state":"California","country":"USA"},
 {"name":"Anderson","state":"Los Angeles","country":"USA"},
 {"name":"Smith","state":"London","country":"United Kingdom"},
 {"name":"Jones","state":"Cambridge","country":"United Kingdom"},
 {"name":"Nathan","state":"Franche Comte","country":"France"},
 {"name":"Marie","state":"Paris","country":"France"},
 {"name":"Nastya","state":"St Petersburg ","country":"Russia"},
 {"name":"Dima","state":"Moscow","country":"Russia"},
 {"name":"Linh","state":"Hanoi","country":"vietnam"},
 {"name":"Hoang","state":"Hai Phong","country":"vietnam"},
]

Step6 : .htaccess


                   Add following lines to your .htaccess file


RewriteRule ^search search.php [L]

                  Now you entered search on address bar, the .htaccess redirects you to search.php file. You can get search API using below url types.

                http://www.phponwebsites.com/search?field=nathan&limit=10
                http://www.phponwebsites.com/search?field=nathan
                http://www.phponwebsites.com/search?limit=10
                http://www.phponwebsites.com/search

19 Aug 2014

Create RSS Feed dynamically using PHP and MySQL

                                    You can create RSS feed dynamically using PHP like how you create sitemap dynamically using PHP and MySQL. Before you are going to know create RSS Feed, you should know what is RSS Feed? and why you need to add RSS Feed to your websites?

What is RSS Feed?


                                   RSS expands Really Simple Syndication. It is developed in XML like Sitemap. It is like content delivery vehicle. That means, you created a product, Ii distributes it to all places. Due to this feed, the viewers of your websites can easily find the latest pages of your websites. So there is no need to spend more time to search their desired topics on your web contents. This is the short description about RSS Feed. 

For more details, visit
    RSS Feed in W3schools
    RSS Feed at rss.softwaregarden
    what is RSS Feed
    Definition of RSS Feed at press-feed

Structure of RSS Feed

             
                                   The structure of RSS Feed is described below.


<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
<channel>
    <title>Phponwebsites</title>
    <link>http://www.phponwebsites.com</link>
    <description>Phponwebsites about php related topics like .htaccess, robots.txt, mysql, jquery, ajax, js and also php for php developers</description>
    <language>en-us</language>
    <item>
      <title>PHP</title>
      <link>http://www.phponwebsites.com/p/php.html</link>
      <description>PHP doubts clarified at Phponwebsites</description>
   </item>
  <item>
      <title>MySQL</title>
      <link>http://www.phponwebsites.com/p/mysql.html</link>
      <description>MySQL doubts clarified at Phponwebsites</description>
   </item>
  <item>
      <title>htaccess</title>
      <link>http://www.phponwebsites.com/p/htaccess.html</link>
      <description>Htaccess doubts clarified at Phponwebsites</description>
   </item>
</channel>
</rss>

Generate RSS Feed dynamically using PHP and MySQL


                 Let see how to create RSS Feed dynamically using PHP and MySQL. Follow the below steps to create feed.


1. Create database and table


                  First you create database for store your link details on it. The below MySQL query is used for create database.

                Create database new

 where new is database name

                Use new

The above query is used to use database "new".
                  The MySQL query for create table is,

                Create table links (id int not null auto_increment primary key, name varchar(200), link varchar(200), description varchar(250))

                 Now the table "links" is created. Then store values into table using below query

                insert into table links values('','PHP','http://www.phponwebsites.com/p/php.html','PHP doubts are clarified at Phponwebsites')

                After insert values into table, your table look likes below

insert values into MySQL table for RSS Feed


2. Add header type RSS Feed


                            First you need to add content type of RSS feed. It is represented below.

header("Content-Type: application/rss+xml; charset=ISO-8859-1");


3. Add content to RSS Feed

                         
                            First of all you need to store all links in your database. Then on;y you can retrieve it using PHP. The below example we Retrieve data from MySQL database using mysql_fetch_array in PHP.
After added header, you have to add some name spaces for RSS Feed. Finally add contents to RSS Feed.


<?php
header("Content-Type: application/rss+xml; charset=ISO-8859-1");
echo '<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
<rss
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"
version="2.0">
<channel>
<title>Phponwebsites</title>
<link>http://www.phponwebsites.com</link>
<description>Phponwebsites about php related topics like .htaccess, robots.txt, mysql, jquery, ajax, js and also php for php developers</description>';
       $connection = @mysql_connect('localhost', 'root', '') or die(mysql_error());
       mysql_select_db('new')  or die (mysql_error());
       $query = "SELECT * FROM links order by id desc";
       $rss = mysql_query($query) or die (mysql_error());
       $ImgPath='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwiEMDL1tvD_oaHIph6KkufjJK5hc5m7kwdJoVgkjFJuf4oqWWbSQXNDkuq1-ukdOhgudTe6gou7Al4oAbvJ-oC-ejuZEhre-ue99v02aajGkKGacaDkZPfk09v7DvUzZlJbIoaxNajoMu/s1600/logo5.png';
       while($row=mysql_fetch_array($rss)){
       echo '
<item>
<title>'.$row['name'].'</title>
<link>'.$row['link'].'</link>
<content:encoded>
      <![CDATA[<p align="left">
          <a href="'.$row['link'].'"><img style="background-image: none; " border="0" src="'.$ImgPath.'" />    </a></p>]]>
       </content:encoded>
       <description>'.$row['description'].'</description></item>';
}
      echo '</channel>
</rss>';
?>

               When you run this file on firfox, you will get output like below

Create RSS Feed dynamicall using PHP and MySQL


4. Htaccess


                         Then you have to add below lines to your htaccess file.


                    RewriteRule ^rss.xml$ rss.php [L]

When you type rss.xml in your browser address bar, it redirects to rss.php.

             Finally you got dynamic RSS Feed.

Related Post:
Read data from RSS Feed using PHP
Create json file using PHP and MySQL
Create XML file using PHP and MySQL
PHP : Parse data from XML Sitemap using simplexml_load_file and file_get_elements
Read data from JSON file using PHP
Parse data from XML file using PHP

29 Nov 2013

How to access pages through one page in site using .htaccess

                        You can access all pages from your site through a one page. It can be possible in .htaccess. In this type, you have to specify the other page urls on that one page.

Syntax:
               RewriteRule ^(.*)$ index.php?url=$1 [L]

                    Where, when you try to access any pages in your site, at first your index.php file run. Then it
navigate to where you fixed it to go, it goes to that page. In your index.php should be like this:

                  $url=explode('/',$_GET['url']);
                 if($url[0]=='home.php') {
                   require_once('home.php');
                 }

                        where, you try to access your home.php file, first it comes to index.php and then check whether the home.php page is present or not. It navigates to home.php, if it is present in your site.

You can also hide all your files except home page:

Syntax:
               RewriteRule ^(.*)$ index.php

                  where, whatever you type in your address bar, you should be navigates to your index file.

Related Post:

28 Nov 2013

How to enable short tags in php using .htaccess

                       Mostly you would use ' <?php echo $name; ?> ' tag for display anything you want. You can also display this type of single variable value by <?=$name?>. But sometime your browser doesn't take this tag. On that time, you won't get proper output. So you can be done this by .htaccess.

Syntax:
              php_value short_open_tag 1
                 
                      Now you can use short tag in your site.

It can also done by php.ini file. You've to change in php.ini file. In your php.ini file, find " short_open_tag=off", then change 'off ' to 'on'. Save the changes and restart your WAMP server.


Related Post:

27 Nov 2013

How to redirect to www using .htaccess

                       Type your domain name without www in address bar. Check whether it redirects to your site or give a 301 error message. If you got 301 error message, then you will solve this problem using .htaccess.

Syntax:
              RewriteEngine On
              RewriteCond %(HTTP_HOST) ! ^www.domainname.com$ [NC]
              RewriteRule ^(.*)$ http://www.domainname.com/$1 [L, R=301]

Explanation:
              Where,
                          .htaccess force the all http requests to use either www.domainname.com or domainname.com .
                           HTTP_HOST - represents your domain name.
                           RewriteCond   - check the conditions if you typed domain name is not start with www, it 
redirect to next rewrite rule. 
                           ! ^www.domainname.com$ - means you typed domain name is not start with www.
                           NC - represents not case sensitive.
                           RewriteRule - means it redirect domain name without www to http://www.doaminname.com.
                           ^ - starting
                           .* - one or more characters.
                           $ - ending
                           L - if rule matches, don't process any other rewrite rules below this one.

26 Nov 2013

How to redirect the urls using .htaccess

                        You can redirect the urls from one file name to another. It is possible in .htaccess. It can be done by 'RewriteRule' in .htaccess. The 'RewriteRule' is used to redirect the urls from one path to another. You can make your site urls very simple using RewriteRule method.


Rewrite urls using .htaccess:

                       You can rewrite the urls using .htaccess. When your address bar gets one page, the .htaccess can run another page. The .htaccess rewrite the urls from one page to another. Consider the following example.
Syntax:
                RewriteRule ^ex1.php example.php [L]

Explanation:
                First Rule:
                    when the ex1.php file is going to run, .htaccess file runs the example.php instead of ex1.php.

Hide file extension like php, html using .htaccess:

                             You can hide extensions like .php and .html using .htaccess. Consider the following  example.
                       
Syntax:
                RewriteRule ^home home.php [L]

Explanation:
                    When the browser get home to run, .htaccess runs the home.php instead of home. In this method, you can hide your file extensions like .html, .php .

Remove query string using .htaccess:

                               You can remove query string in address bar using .htaccess. There you can pass values in address bar. Consider the following example.


Syntax:
               RewriteRule ^example/(.*)$ example.php?ex=$1 [L]
Explanation:          
                     it avoids the normal rule.
      ie, example.php?ex=something
                 where,
                           when the browser get example.com/example/something, it considered as example.com/example.php?ex=something. Then you can get this value by $_GET['ex']. In this method, you can make your urls very simple and it is easily remembered by any browser.
                            ^  - starting point
                            .* -  one or more characters
                            $  - end point
                            L  - tells the server to stop trying to rewrite a URL after it has applied that rule.


How to redirect one web page url to another website:


                            Suppose you may have one more sites. If you feel when the users try to access the particular file, it directs to another your website.You can also redirect the urls from one website to another. It can be possible in .htaccess.

Syntax:
                Redirect  302 / site2.php  http://www.example2.com
Explanation:        
                    Where,  302 is the temporary redirect.
                                  When the user access the site2.php file in your current domain, it redirect to example2.com website.    
                         

How to redirect from one site to another:

                             
                                    Suppose you feel when the user access your one site, it redirect to another site. Then it can be done by .htaccess.

Syntax:
              Redirect 302 /   http://www.example2.com

              Now if the user come to your current domain, it will redirect to example2.com.


Related Post:

25 Nov 2013

How to enable or disable the directory lists using .htaccess

                      Your public_html folder should be contain many directories like images, js, styles. Someone may be try to access these files from your site without your permission. If you think, don't allow others to access these files, then you can create .htaccess file for protect your files from them.

Syntax:
               Options -Indexes
                    OR
                IndexIgnore *

           It tells the server to disable the directory listings on your site. Now you can not see your directory lists. If you try to get access it, then you will get forbidden error message.

You can also enable this features to your sire.
Syntax:
               Options +Indexes
           It tells the server to enable the directory listings on your site.


How to ignore the particular file based on its extensions in directory lists using .htaccess:


                        Normally when you access the directory list on your browser, you can get all files presented in that directory. Sometimes, you may be feel, other files will display to user except .php, .css, .js. you can done by .htaccess.

Syntax:
             IndexIgnore .*php .*css .*js

                       Now the user can get access your files except the file with extension php, js and css


How to display the directory lists with other details using .htaccess:


                      By default, the directory lists are displays just with only its name. If you want to know the additional details like its size, description, then you can done by .htaccess.

Syntax:
              Indexoptions +FancyIndexing
                 
                 Now you can get directory lists with additional information such as size, description, last modified date etc..

You can also disable the additional details.

Syntax:
              Indexoptions -FancyIndexing


24 Nov 2013

How to prevent access to php.ini file using .htaccess

                     Php.ini file is the configuration file. Any changes in php.ini file can affect the functionalities of php. It is read each time the php is initialized. By default, php.ini file is located in /user/local/lib directory on your server.  Max_execution_time, shot_open_tag, memory_limit, allow_url_fopen, PHP_INI_SYSTEM, PHP_INI_ALL, PHP_INI_PERDIR are some of the modes present in a php.ini configuration file. It can be easily access by others . We can restrict this by .htaccess.
Example:
        <FilesMatch "\.(js | jpeg | jpg)$">
             Order allow, deny
             Deny from All
             Allow from env=REDIRECT_STATUS
        </FilesMatch>

               Where,
                            You can add any file type by type extension without '.' and each one is separate by '|' .
               OR

       <Files php.ini>
          Order allow, deny
          Deny from all
       </Files>
                      Now your php.ini file is invisible to viewers.


Related Post:

22 Nov 2013

How to force script to display as source code using .htaccess

                       You can display script code as a source code instead of executing.
Syntax:
             RemoveHandler cgi-script .pl .cgi .php .py
             AddType text/plain .pl .cgi .php .py

Explanation:
             where,
                        RemoveHandler - remove all the server-parsed handler associated with the extensions like .pl, .php for all the paths.
                        .cgi - run outside of /cgi-bin/ directory
                        .py -  treat same as a normal HTML file
                        AddType - used to assign a MIME type to a file suffix
                        text/plain - format of file.

Related Post:

21 Nov 2013

How to enable SSI using .htaccess

                      SSI expands Server Side Includes. It is used to allow you can include in your html doucments for call CGI scripts or html documents. Due to this, space of disk is saved.

Syntax:
              AddHandler server-parsed .html
                   
                   It tells the server to allow the server side includes to your content which have the extensions '.html' . But SSI does slow down the server. Because it need to extra stuff before serving up a page

Related Post:

20 Nov 2013

How to add MIME types using .htaccess

                      MIME expands  Multi-purpose Internet Mail Extensions. It is used to classify the file types on Internet.
                     Sometimes, the browser can not understand the file types of a file. At that time, we can instructs to browser, what file type is? using .htaccess. We can also create custom file type using it.
Syntax:
            AddType text/plain .txt
            where,
                        AddType - means that you are adding a new file type to MIME types.
                        text/plain  - MIME type
                                .txt   - extensions
Example:
                 AddType application/pdf .pf
                 AddType application/zip .zip
                 AddType image/jpeg .jpg .jpeg

Most Common MIME Types:

           

     .3dm                - x-world/x-3dmf
      .3dmf               - x-world/x-3dmf
      .a                     - application/octet-stream
      .aab                 - application/x-authorware-bin
      .aam                - application/x-authorware-map
      .aas                 - application/x-authorware-seg
      .abc                 - text/vnd.abc
      .acgi                - text/html
      .afl                   - viedo/animaflex
      .aif                  - audio/aiff
      .aif                  - audio/x-aiff
      .aifc                 - audio/aiff
      .aif                  - audio/x-aiff
      .aiff                  - audio/aiff
      .aiff                  - audio/x-aiff
      .aim                  - application/x-aim
      .aip                  - text/x-audiosoft-intra
      .ani                  - application/x-navi-animation
      .aos                  - application/x-nokia-9000-communicator-add-on-software
      .aps                  - application/mime
      .arc                  - application/octet-stream
      .arj                  - application/arj
      .arj                  - application/octet-stream
      .art                  - image/x-jg
      .asf                  - video/x-ms-asf
      .asm                - text/x-asm
      .asp                  - text/asp
      .asx                  - application/x-mplayer2
      .asx                  - video/x-ms-asf
      .asx                  - video/x-ms-asf-plugin
      .au                  - audio/basic
      .au                  - audio/x-au
      .avi                 - application/x-troff-msvideo
      .avi                 - video/avi
      .avi                 - video/msvideo
      .avi                 - video/x-msvideo
      .avs                 - video/avs-video
      .bcpio             - application/x-bcpio
      .bin                 - application/mac-bimary
      .bin                 - application/macbinary
      .bin                 - application/octet-stream
      .bin                 - application/x-binary
      .bin                 - application/x-macbinary
      .bm                 - image/bmp
      .bmp               - image/bmp
      .bmp               - image/x-windows-bmp
      .boo                - application/book
      .book              - application/book
      .boz                 - application/x-bzip2
      .bsh                 - application/x-bsh
      .bz                   - application/x-bzip
      .bz2                 - application/x-bzip2
      .c                     - text/plain
      .c                     - text/x-c
      .c++                - text/plain
      .cat                  - application/vnd.ms-pki.seccat
      .cc                   - text/plain
      .cc                   - text/x-c
      .ccad               - application/clariscad
      .cco                 - application/x-cocoa
      .cdf                  - application/cdf
      .cdf                  - application/x-cdf
      .cdf                  - application/x-netcdf
      .cer                  - application/pkix-cert
      .cer                  - application/x-x509-ca-cert
      .cha                  - application/x-chat
      .chat                 - application/x-chat
      .class                - application/java
      .class                - application/java-byte-code
      .class                - application/x-java-class
      .com                 - application/octet-stream
      .com                 - text/plain
      .conf                 - text/plain
      .cpio                 - application/x-cpio
      .cpp                  - text/x-c
      .cpt                   - application/mac-compactpro
      .cpt                   - application/x-compactpro
      .cpt                   - application/x-cpt
      .crl                    - application/pkcs-crl
      .crl                    - application/pkix-crl
      .crt                    - application/pkix-cert
      .crt                    - application/x-x509-ca-cert
      .crt                    - application/x-x509-user-cert
      .csh                   - application/x-csh
      .csh                   - text/x-script.csh
      .css                   - application/x-pointplus
      .css                   - text/css
      .cxx                   - text/plain
      .dcr                   - application/x-director
      .deepv               - application/x-deepv
      .def                   - text/plani
      .der                   - application/x-x509-ca-cert
      .dif                    - video/x-dv
      .dir                    - application/x-director
      .dl                     - video/dl
      .dl                     - video/x-dl
      .doc                  - application/msword
      .dot                  - application/msword
      .dp                   - application/commonground
      .drw                 - application/drafting
      .dump              - application/octet-stream
      .dv                   - video/x-dv
      .dvi                  - application/x-dvi
      .dwf                 - drawing/x-dwf (old)
      .dwf                 - model/vnd.dwf
      .dwg                - application/acad
      .dwg                - image/vnd.dwg
      .dwg                - image/x-dwg
      .dxf                  - application/dxf
      .dxf                  - image/vnd.dwg
      .dxf                  - image/x-dwg
      .dxr                  - application/x-director
      .el                    - text/x-script.elisp
      .elc                  - application/x-bytecode.elisp
      .elc                  - application/x-elc
      .env                 - application/x-envoy
      .eps                 - application/postscript
      .es                   - application/x-esrehber
      .etx                  - text/x-setext
      .evy                 - application/envoy
      .evy                 - application/x-envoy
      .exe                 - application/octet-stream
      .f                     - text/plain
      .gif                  - image/gif
      .gl                   - video/gl
      .gsm               - audio/x-gsm
      .gz                  - application/x-compressed
      .gz                  - application/x-gzip
      .gzip               - application/x-gzip
      .gzip               - multipart/x-gzip
      .htc                 - text/x-component
      .htm                - text/html
      .html               - text/html
      .htmls              - text/html
      .htx                 - text/html
      .ico                 - image/x-icon
      .ima                - application/x-ima
      .imap              - aplication/x-httpd-imap
      .jav                 - text/x-java-source
      .java               - text/plain
      .java               - text/x-java-source
      .jpe                 - image/jpeg
      .jpe                 - image/pjpeg
      .jpeg                 - image/jpeg
      .jpeg                 - image/pjpeg
      .jpg                 - image/jpeg
      .jpg                 - image/pjpeg
      .js                   - application/x-javascript
      .js                   - application/javascript
      .js                   - text/javascript
      .ksh                - application/x-ksh
      .list                 - text/plain
      .m1v              - video/mpeg
      .m2a              - audio/mpeg
      .m3u              - audio/x-mpequrl
      .mht               - message/rfc822
      .mhtml           - message/rfc822
      .mif               - application/x-iframe
      .mif               - application/x-mif
      .mime            - message/rfc822
      .mime            - www/mime
      .mod             - audio/mod
      .mod             - audio/x-mod
      .movie           - video/x-sgi-movie
      .mp2              - audio/mpeg
      .mp2              - audio/x-mpeg
      .mp2              - video/mpeg
      .mp2              - video/x-mpeg
      .mp2              - video/x-mpeg2a
      .mp3              - audio/mpeg3
      .mp3              - audio/x-mpeg3
      .mp3              - video/mpeg
      .mp3              - video/x-mpeg
      .nif                 - image/x-niff
      .niff                 - image/x-niff
      .omc               - application/x-omc
      .omcd             - application/x-omcdatemaker
      .omcr              - application/x-omcregerator
      .part                - application/pro-eng
      .pas                 - text/pascal
      .pic                  - image/pict
      .pict                 - image/pict
      .png                 - image/png
      .ppm                - image/x-portable-pixmap
      .pps                  - application/mspowerpoint
      .ppt                  - application/powerpoint
      .qcp                 - audio/vnd.qcelp
      .rpm                 - audio/x-pn-realaudio-plugin
      .rt                     - text/richtext
      .rtf                    - application/rtf
      .sdp                  - application/sdp
      .sgm                  - text/sgml
      .sgm                  - text/x-sgml
      .sgml                 - text/sgml
      .sgml                 - text/x-sgml
      .shtml                - text/html
      .spr                   - application/x-sprite
      .sprite               - application/x-sprite
      .src                   - application/x-wais-source
      .swf                  - application/x-shockwave-flash
      .tex                   - application/x-tex
      .texi                  - application/x-texinfo
      .texinfo             - application/x-texinfo
      .text                  - application/plain
      .text                  - text/plain
      .txt                    - text/plain
      .unv                  - application/i-deas
      .vcd                  - application/x-cdlink
      .voc                  - audio/voc
      .vos                  - video/vosaic
      .wav                 - audio/wav
      .wav                 - audio/x-wav
      .wmf                 - windows/metafile
      .wpd                 - application/wordperfect
      .wsc                  - text/scriplet
      .xl                      - application/excel
      .xla                    - application/excel
      .xla                    - application/x-excel
      .xla                    - application/x-msexcel
      .xlb                    - application/excel
      .xm                    - application/xml
      .z                       - application/x-compress
      .z                       - application/x-compressed
      .zip                    - application/x-compressed
      .zip                    - application/x-zip-compressed
      .zip                    - application/zip
      .zip                    - application/x-zip

Related Post:

19 Nov 2013

How to add expires headers using .htaccess

                      Check your site in  google insights page speed. You will get a error "Leverage Browser Caching", if your server doesn't add caching headers to your site. If you add expires headers to your .htacces file, then you will get better site speed. Expires headers tells browser whether they should request file from browser or whether they should grab it from browser's cache. Its not only reduce the loads of download from server but rahter to reduce the number of http requests for the server.
Example:
        <IfModule mod_expires.c>
             # Enable Expiration
                ExpiresActive On

             # Default Directive
                ExpiresDefault "access plus 1 month"

             # Favicon
                ExpiresByType image/x-icon "access plus 1 month"

             # Images
                ExpiresByType image/jpeg "access plus 1 month"
                ExpiresByType image/jpg "access plus 1 month"
                ExpiresByType image/png "access plus 1 month"
                ExpiresByType image/gif "access plus 1 month"

             # Css
                ExpiresByType text/css "access plus 1 month"

             # Javascript
                ExpiresByType application/javasacript "access plus 1 month"

             # Html
                ExpiresByType text/html "access plus 1 month"

             # Xml
                ExpiresByType application/xhtml+xml "access plus 1 month"

             # Manifest files
                ExpiresByType application/x-web-app-manifest_json "access plus 1 month"
                ExpiresByType text/cache-manifest "access plus 1 month"

             # Media
                ExpiresByType audio/ogg "access plus 1 month"
                ExpiresByType video/mp4 "access plus 1 month"
                ExpiresByType video/ogg "access plus 1 month"
                ExpiresByType video/webm "access plus 1 month"

             # Web feeds
                ExpiresByType application/atom+xml "access plus 1 month"
                ExpiresByType application/rss+xml "access plus 1 month"

             # Web fonts
                ExpiresByType application/font-wof "access plus 1 month"
                ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
                ExpiresByType application/x-font-ttf "access plus 1 month"
                ExpiresByType font/opentype "access plus 1 month"
                ExpiresByType image/svg+xml "access plus 1 month"
        </IfModule>

Explation:
            Where,
                   mod_expires.c allows setting by file type to control how long browsers cache file.
                   ExpiresActive enable the expires.
                   ExpiresByType represents the type of file like image, html ...
                   "access + 1 month" means how long the file type cached by browser.

Related Post:

18 Nov 2013

How to create error document using .htaccess

                      All of you should be get error message from your browser. When you type new page name in your address bar, you will get file not found error if it is not in your site. By default, the browser send this type of error message. But you can create your own error page instead of browser's error message. It can be done by .htaccess. Due to this, your site get strange from others sites.

          Syntax:
               ErrorDocument 404  /404.php
 When site get 404 (ie, file not found) error, file 404.php will run.
Server have lot of error codes like 404. They are following as:
             100 - Continue
             101 - Switching Protocols
             200 - OK
             201 - Created
             202 - Accepted
             203 - Non-Authoritative Information
             204 - No Content
             205 - Reset Content 
             206 - Partial Content
Redirection
             300 - Multiple Choices
             301 - Moved Permanently
             302 - Found
             303 - See Other
             304 - Not Modified
             305 - Use Proxy
             307 - Temporary Redirect
Client Error
             400 - Bad Request
             401 - Unauthorized
             402 - Payment Required
             403 - Forbidden
             404 - Not Found
             405 - Method Not Allowed
             406 - Not Acceptable
             407 - Proxy Authentication Required
             408 - Request Timeout
             409 - Conflict
             410 - Gone
             411 - Length Required
             412 - Precondition Failed
             413 - Request Entity Too Large
             414 - Request-URI Too Long
             415 - Unsupported Media Type
             416 - Requested Range Not Satisfiable
             417 - Expectation Failed
Server Error
             500 - Internal Server Error
             501 - Not Implemented
             502 - Bad Gateway
             503 - Service Unavailable
             504 - Gateway Timeout
             505 - HTTP Version Not Supported

Related Post: