SEO Friendly Links and .htaccess Hacks
I’m going to assume most people know how to activate or edit their own .htaccess files. If you’re not sure how to edit them then visit this link.
htaccess modifications can come in really handy when cleaning up some of the old management systems. For those that use Google Webmaster Tools, this can be a great way to clean up those nasty 404s. Also note the Bing Webmaster Area. Many developers don’t build for SEO purposes and let other guys deal with it later. Sometimes they will even request a fee. Here’s a few tricks to save a couple bucks or clean up some links.
1. Removing variables from your links
Ever wonder how sites that have nice friendly links to customer profiles do it? There are a number of methods but if you use php variables that come out like this:
http://www.mywebsite.com/index.php?profile=customer_name
Apply this short mod to your .htaccess file:
The result:
http://mywebsite.com/profile/customer_name
Nice friendly links that everyone understands. Even the users.
2. SEO Friendly 301 Redirects
This is probably the simplest and most useful htaccess. As developers, we change our minds all the time. If those changes ever include changing post names, moving folders, or just altering a link. Google Webmaster Tools is going to come knocking with a 404 error within the next couple days. Fix it with this:
/new/location can also be a link like http://new_website.com
3. Custom Error Pages
These just help you make a nice polished site. Particularly the 404 error page.
4. Block IPs Using htaccess
Handy when you just don't like someone, or a country, or you just hate that IP block
5. Prevent Hotlinking
I get a lot requests for this one.
For more dry information on .htaccess. Here's a great blog on it:
http://htaccess.wordpress.com/tag/htaccess-mod-rewrite/
htaccess modifications can come in really handy when cleaning up some of the old management systems. For those that use Google Webmaster Tools, this can be a great way to clean up those nasty 404s. Also note the Bing Webmaster Area. Many developers don’t build for SEO purposes and let other guys deal with it later. Sometimes they will even request a fee. Here’s a few tricks to save a couple bucks or clean up some links.
1. Removing variables from your links
Ever wonder how sites that have nice friendly links to customer profiles do it? There are a number of methods but if you use php variables that come out like this:
http://www.mywebsite.com/index.php?profile=customer_name
Apply this short mod to your .htaccess file:
| HTML | | copy code | | ? |
| 1 | |
| 2 | RewriteRule ^profile\/(.*)$ index.php?profile=1 [L,QSA] |
| 3 |
The result:
http://mywebsite.com/profile/customer_name

Nice friendly links that everyone understands. Even the users.
2. SEO Friendly 301 Redirects
This is probably the simplest and most useful htaccess. As developers, we change our minds all the time. If those changes ever include changing post names, moving folders, or just altering a link. Google Webmaster Tools is going to come knocking with a 404 error within the next couple days. Fix it with this:
| HTML | | copy code | | ? |
| 1 | |
| 2 | Redirect 301 /path/to/old/location /new/location |
| 3 |
/new/location can also be a link like http://new_website.com
3. Custom Error Pages
These just help you make a nice polished site. Particularly the 404 error page.
| HTML | | copy code | | ? |
| 1 | |
| 2 | ErrorDocument 401 /error/401.php |
| 3 | ErrorDocument 403 /error/403.php |
| 4 | ErrorDocument 404 /error/404.php |
| 5 | ErrorDocument 500 /error/500.php |
4. Block IPs Using htaccess
Handy when you just don't like someone, or a country, or you just hate that IP block
| HTML | | copy code | | ? |
| 1 | |
| 2 | allow from all |
| 3 | deny from 145.186.14.122 |
| 4 | deny from 124.15 |
5. Prevent Hotlinking
I get a lot requests for this one.
| HTML | | copy code | | ? |
| 1 | |
| 2 | Options +FollowSymlinks |
| 3 | # Protect Hotlinking |
| 4 | RewriteEngine On |
| 5 | RewriteCond %{HTTP_REFERER} !^$
|
| 6 | RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]
|
| 7 | RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/hotlink_f_o.png [nc] |
| 8 |
For more dry information on .htaccess. Here's a great blog on it:
http://htaccess.wordpress.com/tag/htaccess-mod-rewrite/



















































Leave a Reply