PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites

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:

17 Nov 2013

Compressing resource with gzip using .htaccess

                       After you host your site, check the speed of your site in google insights page speed. You may be get less speed for your site if your information is not compressed. Mostly all sever can compress the files before send it to download. If the server didn't do this, you have to do compress your file. It can be done by .htaccess.

Enable compression using mod_deflate() in .htaccess:

                     Gzip is a server process that compress your files on fly before transmission to the user. It is used to compress text files like html, css and javascript. It reduces the visitor time and your bandwidth. Due to compression, the speed of your site will be increased.
Example:
                <IfModule mod_deflate.c>
                      AddOutputFilterByType DEFLATE text/text
                      AddOutputFilterByType DEFLATE text/plain
                      AddOutputFilterByType DEFLATE text/html
                      AddOutputFilterByType DEFLATE text/css
                      AddOutputFilterByType DEFLATE text/xml
                      AddOutputFilterByType DEFLATE application/x-javascript
                      AddOutputFilterByType DEFLATE application/javascript
                      AddOutputFilterByType DEFLATE text/javascript
                </IfModule>
Explanation:
            Where,
                         mod_deflate.c provides the output filter ' DEFLATE ' which is used to compress the file in your browser before send it to download.

Enable compression using mod_gzip() in .htaccess:

                 
     
                <IfModule mod_gzip.c>
                       mod_gzip_on Yes
                       mod_gzip_dechunk Yes
                       mod_gzip_item_include file .(html? | txt | css | js | php | pl )$
                       mod_gzip_item_include handler ^cgi-script$
                       mod_gzip_item_include mime ^text/.*
                       mod_gzip_item_include mime ^application/x-javascript.*
                       mod_gzip_item_exclude mime ^image/.*
                       mod_gzip_item_exclude rspheader ^Content-Encoding: .*gzip.*
               </IfModule>
               

You can also done by your php file. Just add this to your header file.
<?php
           if(substr_count($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip')) ob_start('ob_gzhandler');
           else
           ob_start();
?>
After add this content to your .htaccess file, you can check whether your site is compressed or not in  website.

Related Post:

15 Nov 2013

Restrict users to access pages from site using .htaccess

                      Someone may be misuse your information. So .htaccess can be used to restrict unwanted user for accessing your page. It can be done by number of ways, something within that.

Authentication  to your site:

                  In this method, first you have to create user name and password for user who are access your pages. File is saved with name .htpasswd. You've to store your .htpasswd file in .htpasswds folder. You can store it anywhere except in public_html.
  Syntax:
               AuthName "Anything your wish to display on dialog box"             
               AuthType Basic
               AuthUserFile /home/username/.htpasswds/.htpasswd
               Require valid-user
Now anybody try to access your cpanel, the web browser ask username and password.
      where,
                 AuthName     - what you wish to display message on dialog  box to user, when they get to access this page.
                 AuthType Basic - AuthType selects the method that is used to authenticate the user who are try to access particular page on your site. The ' Basic ' method is implemented by mod_auth_basic which sends the password from user to server unencrypted.
                 AuthType Digest is another method supported by the apache server which is implemented by mod_auth_digest.
                 AuthUserFile - where your .htpasswd file located.
                 Require valid-user - tells the server to authentication needed to access this page
You can provide authentication for particular file.
  Syntax:
               AuthUserFile /home/username/.htpasswds/.htpasswd
               AuthType Basic
               AuthName "Anything your wish to display on dialog box"             
               <Files "filename to provide authenticate">
               Require valid-user   
               </Files>
  In password protection method, you can disable it.
  Syntax:
              Require valid-user
              Allow from 127.0.0.1
              Satisfy Any

Deny users by IP Address:

              Some users may be violate your contents. So you have to protect that particular user only. It can be done by .htaccess.
  Syntax:
               order allow, deny
               deny from 192.168.1.1
               allow from all
    where,
              the browser block the users from IP 192.168.1.1
 Considered another example,
  Syntax:
               order allow, deny
               deny from 192.168.1.
               allow from all
 where, the browser block the users from IP address starts with 192.168.1.

You can allow only one user and block all users using it.
  Syntax:
               order allow, deny
               allow from 192.168.1.1
               deny from all
 where, the browser allow the user from IP address 192.168.1.1 only

Deny users by referrer:

               Considered as a example, you host a new site. you may be got referrals. /at this stage, your site have been spammed. This spam will affect the log file. It render your log files useless. We can solve it by .htaccess.
  Syntax:
              RewriteEngine On
              # Options +FollowSymlinks
              RewriteCond %(HTTP_REFERRER) example\.com [NC]
              RewriteRule .* - [F]
   where,
             RewriteEngine On - turn on the mod_rewrite.c
             Options +FollowSymlinks should be start with ' # '. Otherwise it give error message ' 500 Internal Server Error ' .
             RewriteCond %(HTTP_REFERRER) example\.com - it tells server to block traffic from example.com
             [NC] - not case sensitive

You can create multiple referrer.
  Syntax:
              RewriteEngine On
              # Options +FollowSymlinks
              RewriteCond %(HTTP_REFERRER) example\.com [NC, OR]
              RewriteCond %(HTTP_REFERRER) anotherone\.com 
              RewriteRule .* - [F]
  where,
            it says server to block traffic from example.com and anotherone.com.

14 Nov 2013

What is .htaccess

                       Hypertext  access is shortly called as htaccess. It is a directory level configuration file. Directory level means, where you locate your .htaccess file, it configure that directory only. Mostly, on server, it is placed on public_html folder for configure the files to access. You can control your site using it. It is supported by web servers.
   

Uses of .htaccess:


why we use .htaccess

           - DirectoryIndex uses
           - used for restrict the user for access pages from website
           - redirect the urls
           - gives direction to server rather than search engine
           - create error document
           - compressing resources with gzip
           - add expires headers
           - enable and disable the additional functionality of apache webserver
           - prevent access to php.ini file
           - force scripts to display as a source code
           - ensure media files are downloaded instead of played
     

How to start with .htaccess?


   Syntax:
         <IfModule mod_rewrite.c>
             RewriteEngine On
             RewriteCond  %(REQUEST_FILENAME) !-f
             RewriteCond  %(REQUEST_FILENAME) !-d
             RewriteCond  %(REQUEST_FILENAME) !-l
             RewriteBase /
             DirectoryIndex index.php
             RewriteRule ^home index.php [L]
         </IfModule>
  Explanation:
     <IfModule mod_rewrite.c>
                                IfModule test whether mod_rewrite.c is included in apache. If mod_rewrite.c
is included, then it run. Otherwise it doesn't get run.
     RewriteEngine On
                                It tells apache to turn on its RewriteRules.
     RewriteCond
                                RewriteCond execute the next rewrite rules if it is correct.
%(REQUEST_FILENAME) is a variable based on url you request
!-f, !-d, !-l are extension added to regular expression.
where,
         !- f - rewrite condition if it is not  file
         !-d - rewrite condition if it is not directory
         !-l  - rewrite condition if it is not link
 if a file, taken from variable %(REQUEST_FILENAME) does not exist on the file system, then return true.
        RewriteBase /
                              It provide base for RewriteRules.                  
        DirectoryIndex index.php
                              It tells apache to which file is run first when server access to particular directory.
        RewriteRule
                              It redirect the urls.
RewriteRule ^home index.php [L]
      it means, when url get ' home ' on address bar, it runs the file index.php. Using this method, we can change our address bar contents to anything.
          For example,
                 RewriteRule ^sample.html sample.php [L]
                 where,
                            you type sample.html in your address bar, the .htaccess runs sample.php file.
  we can pass the values in address bar using it.
     
Related Post:

13 Nov 2013

Privacy Policy

Privacy Policy for www.phponwebsites.com 

If you require any more information or have any questions about our privacy policy, please feel free to contact us by email at guruparthiban19@gmail.com. 

At www.phponwebsites.com, the privacy of our visitors is of extreme importance to us. This privacy policy document outlines the types of personal information is received and collected by www.phponwebsites.com and how it is used. 

Log Files
Like many other Web sites, www.phponwebsites.com makes use of log files. The information inside the log files includes internet protocol ( IP ) addresses, type of browser, Internet Service Provider ( ISP ), date/time stamp, referring/exit pages, and number of clicks to analyze trends, administer the site, track user’s movement around the site, and gather demographic information. IP addresses, and other such information are not linked to any information that is personally identifiable. 

Cookies and Web Beacons 
www.phponwebsites.com does use cookies to store information about visitors preferences, record user-specific information on which pages the user access or visit, customize Web page content based on visitors browser type or other information that the visitor sends via their browser. 

DoubleClick DART Cookie 
.:: Google, as a third party vendor, uses cookies to serve ads on www.phponwebsites.com.
.:: Google's use of the DART cookie enables it to serve ads to users based on their visit to www.phponwebsites.com and other sites on the Internet. 
.:: Users may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy at the following URL - http://www.google.com/privacy_ads.html 

Some of our advertising partners may use cookies and web beacons on our site. Our advertising partners include ....
Google Adsense


These third-party ad servers or ad networks use technology to the advertisements and links that appear on www.phponwebsites.com send directly to your browsers. They automatically receive your IP address when this occurs. Other technologies ( such as cookies, JavaScript, or Web Beacons ) may also be used by the third-party ad networks to measure the effectiveness of their advertisements and / or to personalize the advertising content that you see. 

www.phponwebsites.com has no access to or control over these cookies that are used by third-party advertisers. 

You should consult the respective privacy policies of these third-party ad servers for more detailed information on their practices as well as for instructions about how to opt-out of certain practices. www.phponwebsites.com's privacy policy does not apply to, and we cannot control the activities of, such other advertisers or web sites. 

If you wish to disable cookies, you may do so through your individual browser options. More detailed information about cookie management with specific web browsers can be found at the browsers' respective websites. 

About me

                       Welcome to my blog. I'm guru who is coming from India. I'm a php web developer.
                       As i'm a php developer, i want to share about php related topics. In this blog, the contents are what i learned from my professional. When i create a page, what are the doubts i got, which is present in this blog. A website should be needs html, css, js, jquery, ajax, mysql, .htaccess, robot.tx and languages like php. If you wish to get more traffic on your site, SEO is the most vital. I shared here some of above represented .
                       If you wish to contact me, please use one of the following media:
           

phponwebsites.comphponwebsites.comphponwebsites.comphponwebsites.comphponwebsites.com phponwebsites.com gurumoorthi who is author of phponwebsites.com at linkedin