Friday, June 25, 2010

10 htaccess Hacks Every SEO Should Know

by ssrivastav on 25 June 2010

There’s a lot that you can do with an htaccess file, and of course, things can get pretty advanced in a hurry. Here, we’re going to keep things pretty simple. These are the 10 basic htaccess hacks that every webmaster should know.
1. Force Caching with htaccess
Use: The following htaccess code won’t help the initial pageload, but it will significantly help subsequent pageloads by sending 304 status when requested elements haven’t been modified.
FileETag MTime Size
ExpiresActive on
ExpiresDefault “access plus x seconds”
I generally set the cache for one day (86400 seconds). You can also set different expirations for each file type by breaking each file type up into separate ExpiresByType lines such as:
ExpiresByType image/gif “access plus x seconds”
ExpiresByType text/css “access plus x seconds”
Simple!
2. Set a Custom 404 Page with htaccess
Use: I think this one is self explantatory. Just change ‘/notfound.html’ to match the path to your custom 404 page.
ErrorDocument 404 /notfound.html
3. Implement a 301 Redirect with htaccess
Use: If you have permanently changed the URL structure on your site (via either optimization change or CMS migration), you will want to implement 301 redirects from the old URL to the new URL.
The syntax for a basic 301 redirect is:
Redirect 301 relative/path/to/oldurl/ http://www.domain.com/newurl/
Explanation:
The first URL should be a relative path to the old URL and the second one should be an absolute path to the new URL.
4. Only allow specific IP addresses in certain directories
This is especially useful for admin directories. I generally set my home IP and work IP as the only allowable IPs who can even attempt a login. Unlike other .htaccess hacks, this one doesn’t work from the root folder. You will need to create a new .htaccess file, put the following code in it, and upload it to your admin directory.
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName “Example Access Control”
AuthType Basic
order deny,allow
deny from all
allow from xx.xx.xx.xx
To allow a second IP, just add another ‘allow from’ line.
5. Prevent Image Hot Linking with htaccess
Removed. Here is a MUCH better way to go about this thanks to Maurizio Petrone
6. Enable gzip with htaccess
Gzip is a means of compressing the files on your server so they will load faster. To enable gzip, just
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
7. Remove ‘category’ from a URL with htaccess
Many content management sytems use the ‘category’ URL segment. For instance:
http://makeitrank.com/category/category-name
Well, that’s fine, and it’s necessary to make the CMS work the way it’s supposed to, but it doesn’t need to be visible to do its job. Just drop the following code into your htaccess file to get rid of it.
RewriteRule ^category/(.+)$ http://www.yourdomain.com/$1 [R=301,L]
8. Define any page as the home page with htaccess
You can set any page as the homepage by adding the following to the htaccess file in your root directory.
DirectoryIndex myfile
9. Disable Directory Browsing
You want to keep people out of any directories that might reveal security weaknesses — for instance, plugin directories.
You can block vistors from browsing the directories by adding the following line to the htaccess file in the directory you’d like to block:
Options All -Indexes
10. Protect your htaccess file
Lastly, you want to protect your htaccess file. Hopefully your host has protected it for you, but you can’t be too safe with these things. The following hack will prevent anybody from accessing your htaccess:

order allow,deny
deny from all

Are there any useful htaccess hacks I’ve left out? Let me know!

Friday, June 11, 2010

How To Optimize Images To Increase Rankings

How To Optimize Images To Increase Rankings - A Short List

Now, here is a list of things to keep in mind when optimizing for images.

1. Give an appropriate filename for images on your website. If the image is a picture of a green frog. Then name it something like green_frog.gif.

2. If possible, the title of the page should match the keyword. This strengthens the effect of an image to a search engine, and further reinforces what your page is about.

3. Make sure you image is not blocked by a referrer link, JavaScript, or similar. There can be many reasons to use a referring link, but if there is none then do not block the source of an image.

4. Use standard path, instead of JavaScript.

5. Use an appropriate ALT attribute with the keyword in the img tag.

6. Use an appropriate TITLE attribute with the img tag.

7. Text NEAR the image should be appropriate. Text near an image also can tell a search engine more about the images it's indexing. Keep this in mind when writing content or ad copy around your images.

8. Use spaces, hyphens, or underscores in naming your images. This separates keywords, thus making them easier to identify.

9. Where the ALT or TITLE attribute is located in the img tag does not matter. An attribute is an attribute and where is located makes no difference to a screen reader or a search engine.

10. Keep keywords and relevant comments in the ALT and TITLE tags to a minimum. You don't want to get penalized by a search engine for spamming with too many keywords crammed into a tag. Plus doing so will not do much for your either. Use only what it takes to identify the image.

11. Search for your images in Google or AllTheWeb. Do a search with Google's Image search to see if you can locate your images in the search results. The particulars of ranking images are more controllable than websites, so the results should allow you to see changes more clearly.

12. The Red Button - If you do not want your images present in the search engines for what ever reason, then the magic red button to turn them off is using your robots.txt correctly. Put a disallow line to block your /images/ directory from all user-agents or select search engine robots. Likewise, if you are blocking your /images/ directory and can't seem to find you images in Google then may you should remove the disallow line. For more information about robots.txt please visit here: http://www.robotstxt.org/wc/robots.html


Adding simple alt and title tags to an img tag may not seem to be too important. But it can be go a long way if it's the little extra push you need to rank better in the search engines.