Tagged: code Toggle Comment Threads | Keyboard Shortcuts

  • Peter Mahoney 11:43 am on February 9, 2016
    Tags: code, code snippets,   

    Quick dirty PHP redirect 

    For when you need to do it and just do it quickly.

    <?php header('Location:http://www.yoursite.com/new_page.html'); ?>
    Permalink | Reply
     
  • Peter Mahoney 12:00 pm on July 17, 2013
    Tags: 301, code, domain, , move address, redirect,   

    Permanently moving website to a new domain 

    You really want to add this to your .htaccess file:

    Redirect 301 / http://your-new-domain

    Let’s break that down.

    • “Redirect” is pretty obvious, it tells the web server to redirect the request.
    • “301” is a special code that tells any search engines that come by that this change is permanent, and they should update their results to reflect the new URL. (Using “302” instead would set it as a temporary move.)
    • “/” just means the entire site, from the very top directory has been moved.
    • http://your-new-domain&#8221; or indeed, whatever your new URL is, is the new domain that all requests should be sent to. Note the final “/” on the end.

    Easy peasy! Now all bookmarks, and search engine results will still be valid and get people to your new address, with one short piece of code.

    Permalink | Reply
     
  • Peter Mahoney 10:33 am on March 4, 2013
    Tags: code,   

    http://petermahoney.net/search-engine-optimisation-seo-code/

    Permalink | Reply
     
  • Peter Mahoney 2:34 pm on February 21, 2013
    Tags: code, , snippets   

    Displaying code snippets easily 

    With the new site and all I’ve some CSS to get through.

    I wanted to make the “pre” element work as a code snippet display for me, and needed a fix to get it to wrap text (since the “width” attribute has been defunct for some time).

    Here’s the solution!

    pre {
     background-color: #F2F2F2;
     padding: 5px 5px 5px 5px;
     white-space: pre-wrap;       /* css-3 */
     white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
     white-space: -pre-wrap;      /* Opera 4-6 */
     white-space: -o-pre-wrap;    /* Opera 7 */
     word-wrap: break-word;       /* Internet Explorer 5.5+ */
    }
    Permalink | Reply
     
    • Peter Mahoney 12:33 pm on March 1, 2013

      Sadly with WordPress in particular this isn’t much help, because php code still gets executed rather than displayed.

      I do recommend “SyntaxHighlighter Evolved”, a plugin that makes displaying code pretty damn simple.

      Permalink | Reply
  • Peter Mahoney 1:18 pm on October 30, 2012
    Tags: code, , , , , web server   

    Speeding up your site 

    There is a slew of methods to speed your site up–which is not only the polite thing to do for your guests–but helps with Speed Engine Optimisation (SEO) too. Google in particular looks at how quickly your site loads when deciding how to rank your site.

    Now, if you’re familiar with web servers then everythign you need to know is written below. If not, this is the sort of thing you want to have an expert do for you; a faster site is too good an opportunity to pass up.

    Browser caching is a process whereby we’re able to reduce the number of HTTP requests the server needs to process, which reduced page load times. Your server tells the visitor’s browser not to look for certain filkes everytime–usually the file that don’t change often anyway.

    Edit your .htaccess file for your site, and include this code:

    ## EXPIRES CACHING ##
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType text/css "access 1 month"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresDefault "access 2 days"
    </IfModule>
    ## EXPIRES CACHING ##

    Restart your web server, and you’re done!

    Cache that, baby.

    Permalink | Reply
     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel