Page 44 - Payout Magazine Online Volume 8.0
P. 44

com/page.php” becomes “yoursite.com/page.  rewriteengine on
                                               html”.                                  RewriteBase /scripts/

                                                The second method parses all static pages as   RewriteRule  ^thesescripts/.html$  scripts.php
                                               dynamic. This seems contrary to the goal, but   [T=application/x-httpd-php]
                                               it  isn’t.  What  happens  in  this  scenario:  your
                                               entire site appears as a static site while, in truth,   RewriteRule ^allscripts/.html$ anotherscript.
                                               generates via dynamic pages. The difference   cgi [T=application/x-httpd-cgi] [L]
                                               lies in the whole of the site rather than a single
                                               page. All of your pages will appear as “page.html”
                                                                                      explaining the rules
                                               rather than “page.php”.
                                                                                       ^thesescripts/  – Tells the server whether the
                                                                                      page starts with the specified name.
                                               Locating the .htaccess File
                                                The server typically creates a default .htaccess   / .html$ – Tells the server that, after the match,
                                               in the public_html directory.          the only other characters to find are the .html.
                                                                                      Upon finding anything else, it ignores the file.
                                                “/home/username/public_html/.htaccess”.
                                                                                       php$  –  The  file  name  change  loaded  by  the
                                                Often  times  you’ll  have  to  unhide  the  file   server.
                                               through your CPanel settings. If you’re working
                                               via a remote server, check your  root folder.   [T=application/x-httpd-cgi]  –  This  tells  the
                                               Remember to unhide the files. If you find there   server to change the MIME type so that it runs
                                               isn’t  an  .htaccess  file,  you  can  create  one  by   the page accordingly.
                                               creating a new file and naming it .htaccess. Save
                                               it to your root directory.              [L] – Stops all further rules from executing as
                                                                                      long as the previous rules were successful.

                                               Masking Dynamic as Static
                                                                                      Parsing Static as Dynamic
                                                To change select pages to appear as static open
                                               your .htaccess in your editor of choice. Let’s   Parsing  all  static  files  as  dynamic  has  fewer
                                               assume the name of the file is “scripts.php” and   steps than a single page. For this step, you won’t
                                               you want it to show as “thesescripts.html”.  need  the  mod_rewrite  module  loaded.  If  you’d
                                                                                      like all dynamic files to appear as static, you need
                                                                                      only add to your .htaccess file the following:
                                               add the following rewrite rule:
                                                RewriteEngine on #Text after the octothorpe
                                                                                      addType application/x-httpd-
                                               (hashtag) are comments.
                                                                                      php .html
                                                RewriteBase /scripts/ #This is the folder where   In order for this to work effectively, you’ll name
                                               the rewrite rule applies.              your scripts with an HTML extension. The above
                                                                                      code will parse all your files as PHP despite having
                                                RewriteRule  ^thesescripts\.html$  scripts.php   an HTML extension.
                                               [T=application/x-httpd-php] #Changes ‘scripts.
                                               php’ to ‘thesescripts.html’.
                                                                                      Yes or No
                                                                                       While using the .htaccess file to mask or parse
                                                Hint: When you save your file and are creating
                                                                                      your scripts is an effective method, it may not
                                               a  new  file,  if  you’re  saving  using  Notepad  (not
                                                                                      be the most efficient. Depending on the volume
                                               Notepad++),  you’ll  save  the  file  as  “.htaccess”
                                                                                      of traffic you receive, the site load speed slows
                                               and  include  the  quotation  marks.  Otherwise,
                                                                                      drastically.
                                               Notepad will append “.txt” after the name.
                                                                                       However, if you have just a few scripts or need
                                               adding Files                           to address a few inconsistencies within your file
                                                It’s also possible to add additional rules. For   structure, there’s no harm in masquerading your
                                               instance,  if  you’d  like  to  add  a  secondary  file   CGI/PHP scripts. After all, it’s a rather useful
                                               named “anotherscript.cgi” and change it to   tool to keep within your arsenal of development
                                               “allscripts.html”.                     tactics, as you’ve seen.


       44 PAYOUTMAGAZINE                                                                Sponsored by
   39   40   41   42   43   44   45   46   47   48   49