background preloader

Htaccess

Facebook Twitter

10 useful .htaccess snippets to have in your toolbox. .htaccess, the file which control the Apache webserver, is very useful and allows you to do a lot of things.

10 useful .htaccess snippets to have in your toolbox

In this article, I have compiled 10 .htaccess snippets that any web developer should have in his toolbox. Before editing your .htaccess file, always make a backup so you can restore it if needed. Remove www in url For SEO reasons, you might always remove (or use) the www prefix in your urls. The following snippet will remove the www from your website url and redirect any url with the www to the non-www version. RewriteEngine On RewriteCond %{HTTP_HOST} ! Source: Prevent hotlinking Hotlinking is a bad practice that consist of using the images from another site on yours. Source: Redirect all WordPress feeds to feedburner Most bloggers are using Feedburner, a web service that lets you know how many people are reading your blog via feeds.

<IfModule mod_alias.c> RedirectMatch 301 /feed/(atom|rdf|rss|rss2)/? Source: Create custom error pages Tired of the old errors pages of your site? Source: URL Rewriting for Beginners. A beginner's guide to URL rewriting, with plenty of examples.

URL Rewriting for Beginners

Introduction URL rewriting can be one of the best and quickest ways to improve the usability and search friendliness of your site. It can also be the source of near-unending misery and suffering. Definitely worth playing carefully with it - lots of testing is recommended. With great power comes great responsibility, and all that. There are several other guides on the web already, that may suit your needs better than this one. Apache URL Rewriting Guide - The best guide around Before reading on, you may find it helpful to have the mod_rewrite cheat sheet and/or the regular expressions cheat sheet handy. What is "URL Rewriting"? Most dynamic sites include variables in their URLs that tell the site what information to show the user. The problems with this kind of URL structure are that the URL is not at all memorable. Clearly a much cleaner and shorter URL.

Now we're getting somewhere. Platforms and Tools Basic URL Rewriting number} 10 htaccess Hacks Every SEO Should Know. There’s a lot that you can do with an htaccess file, and of course, things can get pretty advanced in a hurry.

10 htaccess Hacks Every SEO Should Know

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 SizeExpiresActive on ExpiresDefault "access plus x seconds" I generally set the cache for one day (86400 seconds). ExpiresByType image/gif "access plus x seconds"ExpiresByType text/css "access plus x seconds" Simple!

2. Use: I think this one is self explantatory. ErrorDocument 404 /notfound.html 3. 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: