Regex tips and tricks

Posted on November 23, 2012 by admin.
Categories: html tips, Linux tips and tricks.

To search for numbers (regex still considers them text)

[0-9] means any single digit with the character value of 0 – 9. (Won’t match letters)

  • ex: to find or match: 2011/02/10/ use: 201[0-2]/[0-9][0-9]/

Great guide on regex:

http://www.regular-expressions.info/numericranges.html

Cleaning up text using PHP – remove line breaks and paragraphs and tabs and replace with an empty space

Posted on March 10, 2012 by admin.
Categories: css tips, html tips, Web Development Tricks.

Cleaning up text using PHP – remove line breaks and paragraphs and tabs and replace with an empty space.

Cannot see new version of website – updates not showing – sticky cache

Posted on February 13, 2012 by admin.
Categories: css tips, Google tips and tricks, html tips, Web Development Tricks.

1) Control-R (or Command-R) – Control – F5 does the same thing on Windows

2) Go through your options and empty the cache manually

3) Try another browser

Users do not normally notice the old website hasn’t changed because they are not talking to the developers and wouldn’t know when the website really has been updated. This happens all the time.

Most likely you have a “sticky cache” on your computer.

Here’s the trick: Whether you get to http://yourwebsite.com by clicking this link, or by going through google, once you see http://yourwebsite.com in the top line of Internet Explorer, Firefox or Chrome (The URL or Location bar), do a hard refresh.

Hard refresh is done when you are supposed to be seeing the new webpage that you are having trouble with, and reaching out to your keyboard, while holding the “control” key, tap and letup on the “r” key, then let go of the “control” key. (Ctrl-r)

This dumps the old cached page that is sitting on your computer and tells it to go load the new one from the internet.

This insures that you are seeing the latest changes to your website.

The “sticky cache” issue is common when developing new websites. Usually people don’t notice changed pages so much because they don’t know the page should have changed. It happens more often than people realize.

Note: If you have an alternate web browser installed that you haven’t used lately, just view the website in it, you should see the latest version automatically, since it’s not been “cached” lately. Browsers do not share each other’s cache.

—-

If you have a really sticky cache:

Log out of WordPress, clear your browser cache, quit and restart the browser and try again. If that does not work, there may be a caching proxy or network cache somewhere between you and your host. You may need to wait for a few hours until this cache expires.

—-

Note: CSS changes can cause a really sticky cache when background images are changed, they tend not to update unless you clear your cache.

Permanent 301 Redirect the easy way

Posted on May 12, 2009 by admin.
Categories: html tips, SEO.

First, .htaccess and mod_rewrite can be very tricky and if you break your website redirect you may even fix it and not know because your browser session has not been restarted.

Use [R] instead of [R=301] while you are testing . When you are 100% certain the rule does exactly as it’s expected to, then switch it to [R=301] for your live site.

How to redirect any and all website pages to another website removing the page reference. This way if you have an old website with old links everyone will be redirected to the front door. Search engines will see the permanent 301 redirect and update their index to not list your old website.

# redirect anything with base url in the second line to the first one and remove any page references
redirectMatch 301 ^(.*)$ http://mynewwebsite.com
redirectMatch permanent ^(.*)$ http://www.myoldwebsite.net

Redirect with URL masking:
from: http://answers.yahoo.com/question/index?qid=20090904141904AAd3mjB
“the apache rewriteengine doesn’t have any functionalities to mask URLs. Traditional masking techniques (pull out the source of the page that’s been masked and you’ll see) is done through a frame.


However you can accomplish dynamic masking by a little bit of additional code (I have an example in django but it’s out of the scope of this discussion.)

Here’s a basic masking frame

<frameset rows = “100%, *” border = “0″ framespacing=”0″ frameborder=”0″>

<frame noresize = “” src = “http://yourwebsite.com/”></frame>

</frameset>

@EDIT:

That would be for contemporary redirects.

Let’s say that you want host1.com to redirect to mysite.com

The usual .htaccess redirect rule would be

RewriteEngine on
RewriteCond %{HTTP_HOST} ^host1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.host1.com$
RewriteRule ^.*$ “http://mysite.com/” [R=301,L]

in apache.

(The string of ” acts as escape sequences for [':','/','.'], with a R response code of 301)

However this does not allow you to mask the pages.

In order to achieve masking effects, use the following as your HTML in the index.html file on host1.com

<frameset rows = “100%, *” border = “0″ framespacing=”0″ frameborder=”0″>

<frame noresize = “” src = “http://mysite.com/”></frame>

</frameset>

Just copy paste this into the index.html file under host1.com and it should work.”

More .htaccess tricks with various redirects and how to do them:

from: http://corz.org/serv/tricks/htaccess2.php

My HTML tips and tricks

Posted on March 1, 2009 by admin.
Categories: html tips.

Extra spaces inside tables, usually at the bottom of the td (table cell) and hanging bottoms after forms.

This is assuming you don’t have problems with the cellpadding and cellspacing not being set explicitly to 0. You can have tables with cellpadding and cellspacing and still not have that annoying space below your content at the bottom of the table! Read on…

In the old days, the extra space at the bottom of a table was due to having the </td> on the next line after the content inside the table. To make the code readable, most people and web page creation programs will put the closing table data tag on it’s  own line. This creates the problem. The workaround is to close the table data on the same line and don’t leave extra content like a space before the </td> tag.

If you still have the problem: HTML rendering engines in the browsers add spaces before and after block level elements including forms. They almost always suppress the space before the form and only show the space after. If you are using style sheets (refer to my css tricks), you can easily defeat this by specifying a margin of 0.

If you still have the problem and are using pure HTML without css:
You can add just a bit of css to fix your entire page, not your entire website, that would require declaring an external stylesheet on every page. Put this inside your head tag:
<style>
h1, h2, h3, h4, h5{margin:0px}
</style>

Just substitute whatever block level element is giving you problems with the extra space below.

Image not showing or broken image icon:

1) “View Image” in your browser and look at the file path in the URL bar, that will tell you where the webpage code is saying the image is supposed to be. Put the image up at that path or edit the webpage code to reflect the actual location.

2) Make sure you don’t have a meta tag <base href=”http://www.mywebsite.com/” />  which is telling the webpage to locate image files that are relative linked to look in a certain location with a base path and then add the filename to that. If you do have the meta base href tag, you can change your webpage code to look in an “images/myimage.jpg” folder.

My .htaccess tricks

Posted on January 14, 2009 by admin.
Categories: html tips, Web Development Tricks.

To show a directory listing specifically in that directory only place this in the .htaccess file that resides in that folder:

IndexOptions -FancyIndexing
 Options +Indexes




To deny a directory listing, place this the the .htaccess in that directory or in a higher directory:

 Options -Indexes
 

Now a 403 error will be returned instead.



To redirect to a subdirectory or a folder:


RewriteEngine On
RewriteBase /
RewriteRule ^index.(.*)?$ http://domain.com/subfolder/ [r=301]

This will redirect any attempt to access a file named index.something to your subfolder, whether the file exists or not.

A simple HTML redirect is an alternative:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"></HEAD>
<BODY>
Optional page text here.
</BODY>
</HTML>