vBulletin SEO Forums

SEO

vBulletin Search Engine Optimization

Buy vBSEO Now! HACKER SAFE certified sites prevent over 99.9% of hacker crime.
ne nw
vBSEO Total Support Team Launches DeskPro New vBSEO Discount Level for Network Builders vBSEO 3.2.0 GOLD Has Landed Success with vBSEO = 600ore Web Visitors + $1400 in a Day! Crawlability Inc. Files for SEO Technology Patent
se sw

.htaccess tutorial and some useful examples

This is a discussion on .htaccess tutorial and some useful examples within the Member Articles forums, part of the Focus on Members category; The apache web server provides a feature called .htaccess file, which in a nutshell provides commands for a website. This ...

Go Back   vBulletin SEO Forums > Focus on Members > Member Articles

Enhancing 80 million pages.

Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read
  #1  
Old 03-03-2008, 04:41 PM
Jason_A's Avatar
Senior Member
 
Real Name: Jason Amison
Join Date: Feb 2008
Location: England
Posts: 278
Blog Entries: 1
.htaccess tutorial and some useful examples

The apache web server provides a feature called .htaccess file, which in a nutshell provides commands for a website. This file is simply a text file containing Apache directives.

Warning: Be very careful when editing the .htaccess file, as one single mistake can stop your site working
.

All you need is a text editor, but I strongly recommend you use something other than notepad. All commands must be placed one one line, so if your text editor as word-wrap enabled, be sure to disable it. Also be sure to upload your .htaccess file in ASCII format, and not binary, otherwise it won't work.

Usuall, your text editor or operating system won't allow you to save a file as .htaccess. If this is the case, just save it as htaccess.txt and upload it to your webserver using your FTP client. After doing that, you should use your FTP client and rename the file to it's correct name.

Also keep in mind that some sites do NOT allow .htaccess files, since they can slow down a server, and some things that they can do can compromise a server configuration that has been specifically setup by the admin. Be sure to ask your host if it is allowed, or if they will allow you to have it enabled - ask and you shall receive.

Below are some useful .htaccess command examples...

Redirects

You can use a .htaccess file to re-direct a specific page, to a new page:
Code:
Redirect /OldDir/old.html http://site.com/NewDir/new.html
Custom error pages

These are very useful for those who make mistakes in typing the url. The most common errors are 404 (page not found) and 500 (internet server error). You can design your site for these errors, by simple adding a command to your .htaccess file... you can use as many as you want for any page you wish, just add the following to your .htaccess file:

Code:
 ErrorDocument 404 /404.html
ErrorDocument 500 /500.htm
The initial slash in the directory location represents the root directory of your site. You can name these errors anything you want, and anywhere within your site.

If you don't want your site to re-direct, and you want it to display a "404 page not found" page, then I suggest you take a look at Keith Cohen great guide HERE.

Enabling SSI

Want to use SSI, but your current host doesn' allow it? Well, you can change that with your .htaccess file. The following lines tell the server that any file named .shtml should be parsed for server side commands:
Code:
AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
If you don't care about the performance hit of having all .html files parsed for SSI, change the second line to:

Code:
 AddHandler server-parsed .shtml .html
Protecting your bandwidth from hot linking

We all know there are people out there who love to steal bandwidth, also known as "hot linking,". This is is linking directly to non-html objects on another server, such as images, etc. The most common practice of hot linking pertains to another site's images. To disallow hot linking on your server, create a .htaccess file with the following command inside, and upload it to the folder of images you wish to protect:

Code:
 RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?YourSite\.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
Replace "Yoursite.com" with your own domain. That will cause a broken image to be displayed if it is hot linked. If you would like to display an alternative image in place of the hot linked one, replace the last line with the following:
Code:
RewriteRule \.(gif|jpg)$ http://www.YourSite.com/hotlink.gif [R,L]
Replace "Yoursite.com" with your own domain and "hotlink.gif" with your image name.Redirect yoursite.com to www.yoursite.com

This is very useful. If search engines find both www and non-www links from other sites to your site, then they may treat http://YourSite.com and http://www.YourSite.com as two different websites with the same content. This means you can get penalized for duplicate content.

Therefore, I recommend you set-up a permanent 301 redirect from YourSite.com to www.YourSite.com:
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^YourSite\.com [nc]
RewriteRule (.*) http://www.YourSite.com/$1 [R=301,L]
Again, replace "Yoursite.com" with your own domain.

Prevent viewing of .htaccess or other files

To prevent users from seeing the content of your .htaccess file, place the following code within it:

Code:
<Files .htaccess>
   order allow,deny
   deny from all
   </Files>
If you want to prevent visitors from seeing another file, just substitute that file's name for .htaccess in the Files specification.


Change the default directory page

Usually, the default directory page is index.php, index.html ect. Many servers allow servers allow a range of pages called index, with a variety of extensions, to be the default page.


What to change it to your very own for whatever reason? For example; name.html... no problem, just add the following to your .htaccess file for that directory:

Code:
Directory Index name.html
I will add more in time, but there are enough for the time being.

Thanks for reading!

Regards Jason

Last edited by Jason_A; 03-04-2008 at 11:29 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook!
Reply With Quote
  #2  
Old 03-03-2008, 08:45 PM
Joe Ward's Avatar
vBSEO Staff
vBSEO Total Customer SupportvBSEO Documenter
 
Real Name: Joseph Ward
Join Date: Jun 2005
Location: Puerto Rico
Posts: 19,743
Blog Entries: 7
Great article. Thank-you Jason.
__________________
Joe Ward / Crawlability Inc.
Support Team Launches New DeskPro Powered Tool Enhanced Support at Your Service

vBSEO 3.2.0 Launched - Maximum Overdrive for Your Web Traffic! Over 100 Instant SEO Optimizations

6X Traffic - $1400 in One Day with vBSEO! Imagine What the vBSEO Patent Pending Technology Can Do For You.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook!
Reply With Quote
  #3  
Old 03-04-2008, 11:29 AM
Jason_A's Avatar
Senior Member
 
Real Name: Jason Amison
Join Date: Feb 2008
Location: England
Posts: 278
Blog Entries: 1
Not a problem at all Joe.

Regards Jason
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook!
Reply With Quote
  #4  
Old 03-16-2008, 12:48 PM
Joe Ward's Avatar
vBSEO Staff
vBSEO Total Customer SupportvBSEO Documenter
 
Real Name: Joseph Ward
Join Date: Jun 2005
Location: Puerto Rico
Posts: 19,743
Blog Entries: 7
Related:
[How to] Setup www.yourdomain.com or yourdomain.com (www vs. non-www) - With .htaccess 301 redirects
__________________
Joe Ward / Crawlability Inc.
Support Team Launches New DeskPro Powered Tool Enhanced Support at Your Service

vBSEO 3.2.0 Launched - Maximum Overdrive for Your Web Traffic! Over 100 Instant SEO Optimizations

6X Traffic - $1400 in One Day with vBSEO! Imagine What the vBSEO Patent Pending Technology Can Do For You.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Hotlink Protection Tutorial (Apache Server - .htaccess files) NeutralizeR Member Articles 13 11-20-2008 04:53 AM
Looking for tutorial ChefTalk General Discussion 2 04-17-2007 03:26 PM
Deep Adsense Tutorial usearchme Google Adsense, YPN, & Other Ad Networks 0 03-28-2007 12:45 PM


All times are GMT -4. The time now is 09:10 PM.


Powered by vBulletin Version 3.8.0 Beta 4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.5 ©2008, Crawlability, Inc.