Sunday, June 17, 2007
Do you know about .htaccess file? - Part 3
Introduction
Although there are many uses of the .htaccess file, by far the most popular, and probably most useful, is being able to relaibly password protect directories on websites. Although JavaScript etc. can also be used to do this, only .htaccess has total security (as someone must know the password to get into the directory, there are no 'back doors')
The .htaccess File
Adding password protection to a directory using .htaccess takes two stages. The first part is to add the appropriate lines to your .htaccess file in the directory you would like to protect. Everything below this directory will be password protected:
AuthName "Section Name"
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user
There are a few parts of this which you will need to change for your site. You should replace "Section Name" with the name of the part of the site you are protecting e.g. "Members Area".
The /full/parth/to/.htpasswd should be changed to reflect the full server path to the .htpasswd file (more on this later). If you do not know what the full path to your webspace is, contact your system administrator for details.
The .htpasswd File
Password protecting a directory takes a little more work than any of the other .htaccess functions because you must also create a file to contain the usernames and passwords which are allowed to access the site. These should be placed in a file which (by default) should be called .htpasswd. Like the .htaccess file, this is a file with no name and an 8 letter extension. This can be placed anywhere within you website (as the passwords are encrypted) but it is advisable to store it outside the web root so that it is impossible to access it from the web.
Entering Usernames And Passwords
Once you have created your .htpasswd file (you can do this in a standard text editor) you must enter the usernames and passwords to access the site. They should be entered as follows:
username:password
where the password is the encrypted format of the password. To encrypt the password you will either need to use one of the premade scripts available on the web or write your own. There is a good username/password service at the KxS site which will allow you to enter the user name and password and will output it in the correct format.
For multiple users, just add extra lines to your .htpasswd file in the same format as the first. There are even scripts available for free which will manage the .htpasswd file and will allow automatic adding/removing of users etc.
Accessing The Site
When you try to access a site which has been protected by .htaccess your browser will pop up a standard username/password dialog box. If you don't like this, there are certain scripts available which allow you to embed a username/password box in a website to do the authentication. You can also send the username and password (unencrypted) in the URL as follows:
http://username:password@www.website.com/directory/
Summary
.htaccess is one of the most useful files a webmaster can use. There are a wide variety of different uses for it which can save time and increase security on your website.
Do you know about .htaccess file? - Part 2
Introduction
In the last part I introduced you to .htaccess and some of its useful features. In this part I will show you how to use the .htaccess file to implement some of these.
Stop A Directory Index From Being Shown
Sometimes, for one reason or another, you will have no index file in your directory. This will, of course, mean that if someone types the directory name into their browser, a full listing of all the files in that directory will be shown. This could be a security risk for your site.
To prevent against this (without creating lots of new 'index' files, you can enter a command into your .htaccess file to stop the directory list from being shown:
Options -Indexes
Deny/Allow Certian IP Addresses
In some situations, you may want to only allow people with specific IP addresses to access your site (for example, only allowing people using a particular ISP to get into a certian directory) or you may want to ban certian IP addresses (for example, keeping disruptive memembers out of your message boards). Of course, this will only work if you know the IP addresses you want to ban and, as most people on the internet now have a dynamic IP address, so this is not always the best way to limit usage.
You can block an IP address by using:
deny from 000.000.000.000
where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will block a whole range.
You can allow an IP address by using:
allow from 000.000.000.000
where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will allow a whole range.
If you want to deny everyone from accessing a directory, you can use:
deny from all
but this will still allow scripts to use the files in the directory.
Alternative Index Files
You may not always want to use index.htm or index.html as your index file for a directory, for example if you are using PHP files in your site, you may want index.php to be the index file for a directory. You are not limited to 'index' files though. Using .htaccess you can set foofoo.blah to be your index file if you want to!
Alternate index files are entered in a list. The server will work from left to right, checking to see if each file exists, if none of them exisit it will display a directory listing (unless, of course, you have turned this off).
DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm
Redirection
One of the most useful functions of the .htaccess file is to redirect requests to different files, either on the same server, or on a completely different web site. It can be extremely useful if you change the name of one of your files but allow users to still find it. Another use (which I find very useful) is to redirect to a longer URL, for example in my newsletters I can use a very short URL for my affiliate links. The following can be done to redirect a specific file:
Redirect /location/from/root/file.ext http://www.othersite.com/new/file/location.xyz
In this above example, a file in the root directory called oldfile.html would be entered as:
/oldfile.html
and a file in the old subdirectory would be entered as:
/old/oldfile.html
You can also redirect whole directoires of your site using the .htaccess file, for example if you had a directory called olddirectory on your site and you had set up the same files on a new site at: http://www.newsite.com/newdirectory/ you could redirect all the files in that directory without having to specify each one:
Redirect /olddirectory http://www.newsite.com/newdirectory
Then, any request to your site below /olddirectory will bee redirected to the new site, with the
extra information in the URL added on, for example if someone typed in:
http://www.youroldsite.com/olddirecotry/oldfiles/images/image.gif
They would be redirected to:
http://www.newsite.com/newdirectory/oldfiles/images/image.gif
This can prove to be extremely powerful if used correctly.
Friday, March 09, 2007
Do you know about .htaccess file? - Part 1
Introduction
In this tutorial you will find out about the .htaccess file and the power it has to improve your website. Although .htaccess is only a file, it can change settings on the servers and allow you to do many different things, the most popular being able to have your own custom 404 error pages. .htaccess isn't difficult to use and is really just made up of a few simple instructions in a text file.
Will My Host Support It?
This is probably the hardest question to give a simple answer to. Many hosts support .htaccess but don't actually publicise it and many other hosts have the capability but do not allow their users to have a .htaccess file. As a general rule, if your server runs Unix or Linux, or any version of the Apache web server it will support .htaccess, although your host may not allow you to use it.
A good sign of whether your host allows .htaccess files is if they support password protection of folders. To do this they will need to offer .htaccess (although in a few cases they will offer password protection but not let you use .htaccess). The best thing to do if you are unsure is to either upload your own .htaccess file and see if it works or e-mail your web host and ask them.
What Can I Do?
You may be wondering what .htaccess can do, or you may have read about some of its uses but don't realise how many things you can actually do with it.
There is a huge range of things .htaccess can do including: password protecting folders, redirecting users automatically, custom error pages, changing your file extensions, banning users with certian IP addresses, only allowing users with certain IP addresses, stopping directory listings and using a different file as the index file.
Creating A .htaccess File
Creating a .htaccess file may cause you a few problems. Writing the file is easy, you just need enter the appropriate code into a text editor (like notepad). You may run into problems with saving the file. Because .htaccess is a strange file name (the file actually has no name but a 8 letter file extension) it may not be accepted on certain systems (e.g. Windows 3.1). With most operating systems, though, all you need to do is to save the file by entering the name as:
".htaccess"
(including the quotes). If this doesn't work, you will need to name it something else (e.g. htaccess.txt) and then upload it to the server. Once you have uploaded the file you can then rename it using an FTP program.
Warning
Before beginning using .htaccess, I should give you one warning. Although using .htaccess on your server is extremely unlikely to cause you any problems (if something is wrong it simply won't work), you should be wary if you are using the Microsoft FrontPage Extensions. The FrontPage extensions use the .htaccess file so you should not really edit it to add your own information. If you do want to (this is not recommended, but possible) you should download the .htaccess file from your server first (if it exists) and then add your code to the beginning.
Custom Error Pages
The first use of the .htaccess file which I will cover is custom error pages. These will allow you to have your own, personal error pages (for example when a file is not found) instead of using your host's error pages or having no page. This will make your site seem much more professional in the unlikely event of an error. It will also allow you to create scripts to notify you if there is an error (for example I use a PHP script on Free Webmaster Help to automatically e-mail me when a page is not found).
You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file:
ErrorDocument errornumber /file.html
For example if I had the file notfound.html in the root direct
ory of my site and I wanted to use it for a 404 error I would use:
ErrorDocument 404 /notfound.html
If the file is not in the root directory of your site, you just need to put the path to it:
ErrorDocument 500 /errorpages/500.html
These are some of the most common errors:
401 - Authorization Required
400 - Bad request
403 - Forbidden
500 - Internal Server Error
404 - Wrong page
Then, all you need to do is to create a file to display when the error happens and upload it and the .htaccess file.
Sunday, October 01, 2006
Increase Site Visitors
See also: Increase Site Visitors; Increase Website Hits
A-Z Tips to Increase Site VisitorsWe said A-Z and we meant it. Here are 26 sure-fire ways to increase web traffic and site visitors to your website. Use some or all of them, and let us know which ones worked best for you.
- Optimize your site (SEO).
Win on the search engines when people search for keyword phrases related to your products or services.
(More about search engine optimization.)
- Get your site listed in directories.
Submit your site to all the major web directories. This will generate traffic directly from the directories themselves and will also help to improve your link popularity. That helps you win on Google!
(More about web directories.)
- Get listed in search engines.
Submit your site to all the major search engines.
(More about search engines.)
- Get links to your site.
Get people with complimentary sites to link to yours. You offer rental kayaks on the beach. Ask the local restaurant owners to link to you, and offer to link to them. Ask the local tour guides, the real estate agents, the night clubs, and everyone else. Links lead to clicks onto your website and help to improve your search engine rankings.
- Buy links to your site.
Buy text links on other websites. That means more spiders stopping by, more people clicking through, and better search engine rankings.
- Buy banner ads.
Buy banner ads on other websites. It helps to build brand recognition.
- Participate in a banner exchange program.
It won't cost you anything, and will lead to a few extra visitors. Plus, you're spreading your brand all over the place.
- Participate in a WebRing.
Connect your site with other sites in your niche.
- Pay for clicks to your site.
Pay for clicks or inclusion on the search engines so that people will see your site in the sponsored links section of the search results when they search for keyword phrases related to your products or services.
(More about pay per click.)
- Set up an affiliate marketing program.
With affiliate marketing, you can either pay per click or pay per customer acquired.
- Use smart public relations (PR).
Get news coverage of your business and your site. Approach online and traditional media. This will often lead to others placing links pointing to your website, which leads to more clicks and also to improved search engine rankings.
- Use E-mail marketing.
Ugly, but effective for the cost. Blast out your special offers, but be nice about it.
- Use off-line marketing.
Promote your site. Put your url on all your license plates. Paint it on your car. Buy newspaper and yellow pages ads with your url. Put up flyers and stickers. Sponsor a little league team. Do anything and everything to spread the word about your website around your city.
- Run regular promotions.
Stage regular giveaways and spread the word about it.
- Get published.
Write articles for publication on other websites. The author profile will link to your site. The article will show that you're an expert.
- Publish yourself.
Write articles for your own site regularly. This will help you to win on the search engines and gives your visitors a reason to come back over and over.
- Ask for reviews.
Ask for reviews of your self-published articles on other webmasters' websites. Ask for reviews of your website, your products, your software, your services. These will usually include links to your articles.
- Write briefs.
Write daily or weekly news briefs focusing in on your industry or specialty area. This keeps your site "fresh" in the eyes of the major search engines and helps you to spread a wide net when fishing for top search engine positions.
- Create a newsletter.
Ask your visitors to sign up for your newsletter, and encourage them to send it along to people they know. Send a newsletter regularly with teasers or lead-ins to your in-depth new articles or with special offers and the latest products.
- Post in chat rooms.
Become active in bulletin boards and chat rooms focusing on your industry. Leave inciteful comments, and people will click on your profile, then visit your site.
- Give away free stuff.
Offer something people want at your site. Give them a reason to come back and get more. Offer free downloads and update them regularly. Offer coupons or discounts. Content content content.
- Give awards for excellent sites in your niche.
This builds more links back to your site and establishes you as a credible reviewer, an expert in your space.
- Run a contest and promote it.
Photo contests, essay contests, goofy contests, random drawings, anything. Example: Messiest Garage in America contest on OfftheFloor.com.
- Join your local business organizations.
Chambers of Commerce and other organizations will often add your site to their member directory. That's an added advantage over the obvious business-building and networking opportunities.
- Create an RSS feed.
Give people another way to interact with your content.
- Be accessible.
Build your site so that it is accessible to all browsers and to PocketPC and Palm Pilot users. Don't forget, people with disabilities buy things too. Make your site Section 508 complaint. Your competition probably hasn't.
We really couldn't stop at Z
Increase Website Hits
First, let's take a hypothetical tour of the process of measuring website traffic. Imagine Hypothetical Jim visiting the home page of a new website he learned about on Google.com. Hypothetical Jim visits the home page, then visits the "About Us" page, which he bookmarks. Later, Hypothetical Stu visits the home page, then leaves the site. Later that evening, Hypothetical Jim returns to the "About Us" page using his bookmark, and clicks on the link to the "Contact Us" page. After looking over the page, he leaves the site.
From the text description above, you can determine that: (1) the site has had 2 unique visitors, Hypothetical Jim and Hypothetical Stu; (2) the site has had three unique visitor sessions (two for Jim and one for Stu); and (3) the site has had 5 pageviews (4 by Jim and 1 by Stu). You may wonder wether to count Hypothetical Jim's second visit to the "About Us" page as a second pageview. Count it.
What you cannot determine from the description above is the number of website hits. A hit is measured every time a specific unique file (HTML files, image files, script files, frames, etc.) is downloaded. In other words, many people refer to the total number of HTTP Requests a user makes as the number of hits the site receives. Since a single web page can be made up of any number of unique files (hundreds even), measuring hits is often meaningless in measuring the success of a website.
In this hypothetical example, the homepage consists of 24 files, so web analysis software will count 24 hits every time a visitor downloads the home page. There are 21 total images, 1 script, and one CSS file (plus the index html file itself). The "About Us" page consists of 14 files, so web analysis software will count 14 hits. There are 11 images, 1 script, and one CSS file (plus the about html file itself). The same goes for the "Contact Us" page.
As you can see, website hits do not consistently correlate with unique visitors, sessions, or pageviews. The only reason to look at hits is to measure the number of HTTP requests that a browser has to make in order to view your page. Generally speaking, the larger the hit count, the slower the download. For that reason, it is best to reduce the number of hits/page until the download speed is optimized.
Savvy media buyers ignore webmasters who claim to have thousands of hits. They measure pageviews, user sessions, and unique and return visitors.
Wednesday, September 27, 2006
Subdomain and .htaccess file
Features ♦ Download ♦ Requirements ♦ Installing the script ♦ FAQ ♦ Copyright, etc.
This free scripts can add numerous sub domains to your website. When the script has been installed, all you need to do to create a new sub domain is a make a new directory. I.e., if you create the directory http://yoursite.com/newdir then the following sub domain will automatically be added: http://newdir.yoursite.com.
Features
- No need to edit any files when you want a new sub domain -- whenever you create a new directory it will automatically function as a sub domain.
- Works even if the visitor enters "www." in front of the URL: http://www.dir.yoursite.com and http://dir.yoursite.com will both redirect the visitor to http://yoursite.com/dir.
- Case insensitive: http://Dir.YourSite.com, http://DIR.YOURSITE.COM, and http://dir.yoursite.com will all redirect the visitor to http://yoursite.com/dir.
- Can be used with or without frames. If you use frames, the location bar in the browser will not change -- i.e., if the visitor enters http://dir.yoursite.com, the location bar will still show this URL when the visitor has been redirected to the new location (http://yoursite.com/dir). If you decide not to use frames, the location bar will change from http://dir.yoursite.com to http://yoursite.com/dir.
Requirements
Before you get too excited, you should know that only a minority of all web hosts meet the requirements of this script. To use Subdomains, you need a web site account with the following features:- Your own domain, i.e. yoursite.com.
- Wildcarded DNS. The script will not function without this feature. To check if your web host offers wildcarded DNS, you can perform the following test: Start your browser, pick a random word (i.e. "asdf"), and enter your domain name with the random word in front of it like this: asdf.yoursite.com. If you can see the front page of your web site in your browser now, your web host offers wildcarded DNS. However, if the browser response is something like "unable to locate the server asdf.yoursite.com", then your web host does not offer wildcarded DNS, and you cannot use Subdomains (unless, of course, you move to a server that offers this feature).
- PHP (version 3 or later). Ask your web hosting company if you don't know if they offer PHP.
- .htaccess. In some cases it is necessary to edit the .htaccess file in order to make the script work. This means that your web host must provide you with the ability to use .htaccess files. If the name of the web server software is Apache, then it is very likely that you can use .htaccess files -- but ask your web hosting company if you are unsure.
Installing the script
- First you need to change the file name of your front page. The front page is the file that visitors to your web site see when they enter http://yoursite.com. The current name of this file is probably "index.html", "index.php", "default.html", or "home.html", but you need to change the name to something else, i.e. "welcome.html", "front_page.html", "page_1.html" or something similar.
- Load the script (index.php) into a plain text editor such as KEdit (Linux) or Notepad (Windows). Edit the variables at the top of the page.
The $domain variable should be set to the name of your domain. Do not include "www.". Do not include any slashes ("/"). Just write the domain name, i.e. "yourdomain.com". The $default_page variable should be set to the file name of the front page of your web site. I.e., if your front page is located at http://yourdomain.com/welcome.html, you should write "welcome.html" here. The $use_frames variable: If you want to use frames, write "yes" -- otherwise write "no". Have a look at the features section of this README file and the FAQ if you don't understand the difference between redirection using frames and redirection without using frames. - Use a FTP program to upload the index.php file to your web site account. The file should be placed in the document root (this means that you should be able to call the file by pointing your browser to http://yoursite.com/index.php). You don't need to chmod the script since it is not a CGI script.
- Now you can try it out. If it works, you're done. If it doesn't work, check the FAQ.
- When you want to create a new sub domain, just make a directory in your document root (i.e. http://yoursite.com/newdir). This will automatically work as a sub domain (http://newdir.yoursite.com). Remember that the name of the directory cannot include CAPITAL LETTERS. If you create a directory named "Newdir", the sub domain thing won't work. If you create a directory called "newdir", it will work.
FAQ
When I enter the URL to my web site, the browser shows a directory listing (a list of all files in the current directory).You need to add the following line to the .htaccess file:
DirectoryIndex index.php index.html index.shtml index.htm
See the .htaccess question in this FAQ if you don't know how to do this.
When I enter the URL to my web site, the browser shows a white page with a lot of PHP code.
You need to add the following lines to the .htaccess file:
AddType application/x-httpd-php .php
AddType application/x-httpd-php3 .php
See the .htaccess question in this FAQ if you don't know how to do this.
How do I edit the .htaccess file?
Well, first of all you need to establish whether there's a .htaccess file in your document root or not. This can be done be performing the following test: Point your browser to http://yoursite.com/.htaccess (note the dot before "htaccess"). If you get a 404 error (File Not Found), there's no .htaccess file in your document root. However, if you get a 403 error ("Forbidden"), there's a .htaccess in your document root. If you don't have a .htaccess file, you will need to make one. Open a text editor, click "New" and write the necessary lines (the lines are shown elsewhere in this FAQ). You should not write anything else besides these lines -- no HTML tags, no PHP tags, etc. When you're done writing the file, upload it to the server and place it in the document root. Perform the test above to make sure the file has been placed in the right location. If there's already a .htaccess file in your document root, all you need to do is load this file into a text editor and add the appropiate lines at the bottom of the file (the lines you need to write are shown elsewhere in this FAQ).
What's the advantages and disadvantages of using frames when redirecting?
There's one big advantage to using frames: The location bar in the browser does not change. I.e., if the visitor enters http://dir.yoursite.com, this URL will remain in the location bar even though the real location is http://yoursite.com/dir. If you don't use frames, the URL in the location bar will change to the actual location (http://yoursite.com/dir in this example). The disadvantage to using frames is the fact that the title of the page will not be shown. Instead, the location will be shown in the title bar. I.e., if the title of the index.html file at http://yoursite.com/dir is "My page", then this title will not be shown if you are using frames. Instead the following title will be shown: "yoursite.com/dir". Another disadvantage of using frames is the fact that visitors cannot bookmark the sub pages of the main page.
What's the difference between the sub domains generated by the Subdomains script and real sub domains?
The price! "Real" sub domains are expensive. If you were to ask your web hosting company to create a sub domain for you, the company would have to change the web server configuration files as well as the DNS server setup. This will of course cost you a lot of money. And this is just the price of one sub domain! With Subdomains you can create as many sub domains as you want. However, "real" sub domains does have one big advantage which those created by the Subdomains script don't: With "real" sub domain, visitors to your web site can enter a URL like this: http://subdomain.yoursite.com/somedir/somepage.html. This will not work with the sub domains created by the script -- only http://subdomain.yoursite.com will work. If the visitor enters the URL http://subdomain.yoursite.com/somedir/somepage.html, he/she will be redirected to http://yoursite.com/somedir/somepage.html.
Copyright, etc.
This script is released under the terms of the GNU General Public License (also known as "GPL").Thursday, September 21, 2006
Website Thumbnail Creators (Website Snapshot Generators)
1. Grab website thumbnail images from other sites.
Some search engines, like http://www.alexa.com, http://www.exalead.com, etc. provide us with website snapshots. Special utility can be written in scripting language (like PHP, Perl, etc.) to grab website image from their search results. Pros:- cheap solution
- small server load since you do not need to create thumbnails on your server
- you become dependent on third-party servers
- most likely you will only be able to get thumbnail for the top page only. These are not generating thumbnails for subpages.
- may slow down your pages load if remote server is performing slow
- some of them can ban your IP for this type of activity. Your tool can use anonymous proxies, but it will slow down page load
- you will not be able to get website thumbnail if thumbnail was not generated yet on provider's site. This means you will often receive "No thumbnail" images.
- thumbnails are usually of predefined size which may not feet your needs
2. Use existing website thumbnail creator services/tools.
Some website thumbnail/snapshot creator tools are currently available for free. You should place a block of provided html on your page and it will show thumbnail (hopefully). The example could be a PHP tool from artViper (http://www.artviper.com/tools.php). It is said that it's a PHP script utilizing a C++ coded DLL to generate website thumbnail. Another example of free website thumbnail creator service would be http://www.websitethumbnails.net Pros:- free (only basic functionality)
- small server load since you do not need to create thumbnails on your server
- you become dependent on third-party servers (sometimes they can be even down)
- most likely you will only be able to get thumbnail for the top page only. Mostly these are not generating thumbnails for subpages, need to pay for extra features.
- may slow down your pages load if remote server is performing slow
- you will not be able to get website thumbnail if thumbnail was not yet generated on provider's site. This means you will often receive "No thumbnail" images.
- thumbnails are usually of predefined size which may not feet your needs
- need to pay for extra features like true color thumbnails, image format, etc.
3. Have your own website thumbnail generator utility.
Solution would be to use/write a custom program which would run on your hosting server, using some browser to render a website thumbnail. The process would look as follows.- Custom written tool receives request to generate website thumbnail for site-thumbnail.com
- It opens browser (as a process invisible to your visitor) on your hosting server, and feeds it with site-thumbnail.com
- Grabs website screenshot from browser (i.e. it gets website thumbnail), and saves it as thumbnail for later use.
- you are not dependent on anyone, full control over thumbnail
- fast, since you do not need to go to another server to get thumbnail
- relatively cheap solution (think it would be more expensive than solution #1)
- can create thumbnail for any page you want, topmost, subpage, etc.
- possibility of making it payed service
- may cause high server load since tool will create thumbnails on your server
- may be incompatible with some hostings
- hosting which allows such type of activity is usually more expensive