Top Articles

Stay In Touch


Affiliate Marketing Forum

FAQ FAQ Search Search Memberlist Memberlist Usergroups Usergroups
Register Register Profile Profile Log in to check your private messages Private Messages Log in Log in

.htaccess tips

Affiliate Marketing Forum Index » Search Engine Optimization
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Aboo



Joined:
21 Dec 2006

Posts:
3


Post Posted: Thu Dec 21, 2006 11:20 am
      Post subject: .htaccess tips

Reply with quote

Below I show some common uses of .htaccess which I use myself on many sites. Many of you will find no new information here, but hopefully it will help some!


Code:
Options -Indexes This causes the server not to list the contents of directories (when there is no index). This keeps people from typing in http://www.example.com/images/ (or any other directory) and getting a list of the files.


Code:
AddType application/x-httpd-php .php .htmThis code tells your server to process PHP code in files with the .htm extension. Some servers allready do this by default, but many do not. You can also add .html to the end (or any other extension) if you like. This will keep you from having to rename files to php if you add scripts in later, and also I just happen to like it more


Code:
ErrorDocument 400 /errors/400.htm
ErrorDocument 401 /errors/401.htm
ErrorDocument 403 /errors/403.htm
ErrorDocument 404 /errors/404.htm
ErrorDocument 500 /errors/500.htm The control panel of many hosts let you set the custom error pages, but doing it directly is just as easy. I use these 5 common ones. Just create your pretty error pages, and point to them in .htaccess.


Code:
redirectPermanent /somepage.htm http://www.example.com/index.htmJust a basic redirect example here. For when you get rid of a page and want all links to it to just point to the index.


Code:
redirectMatch 301 ^/old_directory/(.*) http://www.example.com/index.htmHere we get a little fancier. This is for when you remove an entire directory. It will make any link to that directory (including all pages and sub-pages in it) go back to your main index.


Code:
redirectMatch 301 ^/subsite/(.*) http://www.example.com/$1
redirectMatch 301 ^/subsite http://www.example.com/$1Say you have a sub-site on your domain.. in the 'subsite' directory, and you moved it to its own domain. These two redirects will take all possible link combinations and redirect them to the new domain. Even if the link is like this : /subsite/1/2/3/4/index.php it will redirect to www.example.com/1/2/3/4/index.php. The two lines give you better flexibility. It handles all combinations of trailing slashes, directories/files, and www. prefixes.


Code:
Options +FollowSymLinks
RewriteEngine onThis code gets the server ready for the next few things we will do


Code:
RewriteCond %{HTTP_HOST} ^example.(.*)
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] This bit of code is quite usefull. It will take any links that do not have www in them, and add it to the URL. This means no matter how they link to you, your full domain (with the www) will get the backlink.


Code:
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.example.com/index.htm [R,NC]This is basic hot-link protection code. I did have two other lines added to it (to take care of the times when the link does not contain the www) but if you use the last tip, you do not have to worry about it. Just make sure to put them in order (so the www gets added before the hot-link protection). This will only allow hot-linking from your site. If you want to add another site, just add the appropriate lines.

Now if you want to sometimes allow hot-linking, here is a good method. Create a directory called 'share' (or whatever) and stick in a new .htaccess file with only this line:


Code:
RewriteEngine offThis will counter-act the global .htaccess, and allow hot-linking from whatever directory you stick it in (and sub-directories)
_________________
flow chart maker Dell coupons
Back to top View user's profile Send private message
AllanGardyne
Site Admin


Joined:
02 Jul 2003

Posts:
6302

Location:
by the beach, Australia

Post Posted: Thu Dec 21, 2006 11:23 pm
      Post subject:

Reply with quote

Thanks for the tips.

I see you recommend using "redirectPermanent". Does is make any difference if "redirect 301" is used instead? That's what I'm using.

Also, I'm not sure that I understand the hot-link protection code. Can you give an example of a situation in which it would be used?
_________________
Allan Gardyne
AssociatePrograms.com - You're here. Explore it!
Back to top View user's profile Send private message Visit poster's website
sophist



Joined:
21 Nov 2003

Posts:
595

Location:
Kamloops, Canada

Post Posted: Tue Dec 26, 2006 6:11 am
      Post subject:

Reply with quote

Great list. Thanks
_________________
Business Owners Guide to Going Online What every business owner needs to know about going online
Back to top View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic
Affiliate Marketing Forum Index » Search Engine Optimization
Page 1 of 1 All times are GMT

 

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Newsletter Sign-up

Sign-up Now!

How to make $1000 a month from scratch

Sign-up for our newsletter and receive our 77 page eBook "How to make $1000 a month from scratch".

Best of all it's FREE!

Your Host

Allan Gardyne

Learn from an affiliate veteran.

Your host, Allan Gardyne, has been earning a good living from affiliate programs since 1998.

Want a BETTER article writer? We will write good articles just for you.

Content Kingdom