« Trackback Link ExchangesGoogle Announces Massive Algorithm Change, Declares War On Content Farms »

htaccess for Search Engine Optimization

05/08/11

Permalink 01:44:29 pm, by galidon Email , 667 words   English (US) latin1
Categories: General
Bookmark and Share

htaccess for Search Engine Optimization

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”


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
Source:
Link Building Secrets Revealed

Basically, you should set up your server to rewrite all of your images to a script. The script will control where the user is coming from, and act accordingly: it will show to users coming from image searches the landing page showing the image they've found, and will continue to serve to regular users the image as usual.

If your server runs Apache with PHP and you can use the .htaccess file, you may set it up like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)\.(jpg|jpeg|gif|png|bmp)$ [NC]
RewriteRule (.*) /script.php?imgpath=$1 [PT]
This will tell to your web server to rewrite any URL that ends with a dot which is followed by "jpg", "jpeg", "gif", "png" or "bmp" (case insensitive) to your script "script.php" on your domain root, passing the entire REQUEST_URI as the "imgpath" parameter in the querystring.

Then, in script.php you will check the HTTP REFERER value, and if you find that it contains "images.google.com" (or any other image search engine you may want to include), the script will serve the landing page. In any other case, the image will be shown as usual.


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:

<files .htaccess>

order allow,deny
deny from all

</files>

Source: 10 htaccess Hacks Every SEO Should Know  



back to galido.net

Google Plus Author: Galido DotNet

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.

Please enter the characters from the image above. (case insensitive)

Array

Search

IT Blog Feed

FeedBurner readersFeedBurner FeedBurner readersFeedBurner mofos

Free IT Subscriptions

Special thanks to:

Green Gadgets
For giving us this award!

Restore America!

Tips and tricks for optimizing your site for the web. This Blog contains information on Search Engine optimization based on personal experiences and from knowledge gained from other experts in the IT industry and SEO space. For help with your SEO needs, contacts us - galido.net; 1st page google results for Information Technology Blog out of 244 million (last updated 8-22-09)

Related IT Blog Feeds


XML Feeds

May 2012
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31