vBulletin Search Engine Optimization
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 ...
| |||||||
Enhancing 80 million pages. | Register | FAQ | Members List | Social Groups | Calendar | Search | Today's Posts | Mark Forums Read |
|
#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 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 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 Code: AddHandler server-parsed .shtml .html 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]
Code: RewriteRule \.(gif|jpg)$ http://www.YourSite.com/hotlink.gif [R,L] 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]
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> 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 Thanks for reading! Regards Jason Last edited by Jason_A; 03-04-2008 at 11:29 AM. |
|
#2
| ||||
| ||||
|
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. |
|
#4
| ||||
| ||||
|
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. |
| Thread Tools | |
| |
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 |