Introduction to apache .htaccess
What is .htaccesss?
.htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server', then the .htaccess file is detected and executed by the Apache Web Server software. These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as content password protection or image hot link prevention.
How to use .htaccess
'.htaccess' is the filename in full, it is not a file extension. For instance, you would not create a file called, 'file.htaccess', it is simply called, '.htaccess'. This file will take effect when placed in any directory which is then in turn loaded via the Apache Web Server software. The file will take effect over the entire directory it is placed in and all files and subdirectories within the specified directory.
You can create a .htaccess file using any good text editor such as TextPad, UltraEdit, Microsoft WordPad and similar (you cannot use Microsoft NotePad).
Companies are also now rolling out mobile phone units pre-equipped with text-editors, so if you happen to own one of those you can also use it to create .htaccess files.
Here is an example of what you might include in a .htaccess file.
AuthName "Member's Area Name"
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
require valid-user
ErrorDocument 401 /error_pages/401.html
AddHandler server-parsed .html
This is a fairly advanced example: it enables password protection on the directory; it offers redirection to a custom error page if a user fails to login correctly; and it enables SSI (server side includes) for use with '.html' files. Please don't be put off, it's very simple once you gain a basic understanding and this article provides examples which are ready to go - simply copy, paste and customise. Examples are explained line by line so it is clear exactly what each line does and why you need it.
Once you have created a .htaccess file, which may look similar to the one shown above (or may simply contain one line), you need to upload it. This should be done using a FTP (file transfer protocol) program. You should already have one which you will have used to upload your web site content. If not, many are available free of charge from web sites such as 'Download.com' and we can recommend 'CuteFTP' and 'WSFTP'.
When uploading your .htaccess files, it is very important you upload the file in 'ASCII' mode. 'ASCII' and 'BINARY' are different methods of transferring data and it is important .htaccess files are transferred in 'ASCII' mode and not 'BINARY'. It is likely your FTP software will default to 'BINARY' so look for a 'Transfer Mode' or 'Transfer Type' option in the menus.
Upload the .htaccess file to the directory you would like it to take effect over. Now visit this directory using your web browser as you would for any other document on your web site and check it has worked correctly.
Note, when you upload your .htaccess file it may not appear in the directory listings for files on your web site. Do not worry; this means your server or FTP software is hiding them which should not be an issue.
A possible cause of error is if the file permissions on the .htaccess file are not set correctly. This only occurs on certain servers, but you may like to change the permissions on the file to '755' or 'executable'. You can do this with your FTP software, look for a 'File Permissions' or 'CHMOD' option, and input '0755'.
If your .htaccess file does not work, you should contact your system administrator or web hosting company and ensure they have enabled .htaccess within your account. Some web hosting companies do not allow use without permission. If errors persist, consult this article for advice, or contact your system administrator for advice.
Error documents
Creating custom error pages is very useful, it allows you to show web site visitors a friendly error message, for instance if a URL on your web site does not work. This avoids the unfriendly '404 File Not Found' error and allows you to display a friendly error, explaining possible solutions and guiding the visitor back into your web site content, rather than leaving them frustrated and lost.
To set-up custom error documents, create a .htaccess file following the main instructions and guidance which includes the following text:
ErrorDocument 404 /error_pages/404.html
The above line tells the Apache Web Server to display the document located at /error_pages/404.html (under your domain name/web site address) whenever a 404 (file not found) error occurs.
In this example, we have assumed you have created the error document and called it '404.html' and that you have placed it in a directory called 'error_pages' under your domain name. For example, http://www.yourdomain.com/error_pages/404.html
The document 404.html is a normal HTML document like the others in your web site and can display whatever content you wish, however we recommend including a 'File Not Found' message.
To setup further error documents, for example for '401 Unauthorised', '403 Forbidden', and '500 Internal Server' error messages, create a .htaccess file following the main instructions and guidance which includes the following text:
ErrorDocument 401 /error_pages/401.html
ErrorDocument 404 /error_pages/404.html
ErrorDocument 500 /error_pages/500.html
It's all very well displaying a friendly error message, but more importantly you need to resolve the error. By using a CGI script instead of a static HTML document as the error document allows us to record errors in a database, and resolve them.
This can be achieved very easily thanks to a variety of pre-made solutions which can even show us which errors are received most frequently. Such products can be found on The CGI Resource Index and HotScripts.com.
Redirects
Redirects enable us to direct web site visitors from one document within your web site to another. This is useful for example, if you have moved your web site content and would like to redirect visitors from old links to the new content location.
To set-up redirects, create a .htaccess file following the main instructions and guidance which includes the following text:
Redirect /old_dir/ http://www.yourdomain.com/new_dir/index.html
The above line tells the Apache Web Server that if a visitor requests a documents located in the directory 'old_dir', then to display the document 'index.html' located in the directory 'new_dir'.
You see in this example, the 'old_dir' is the location of the document to be requested by the visitor, and is a document or directory located under your main domain. In this example, the directory 'old_dir' would be located at 'http://www.yourdomain.com/old_dir/'. However, you will also notice the location of the file that the visitor is to be redirected to is a full web site URL, not what is referred to as a relative URL in the case of 'old_dir'. This means we can redirect visitors to the 'old_dir' folder to any web site document, it doesn't have to be held within your web site content and could be any web site.
It is very important (and the most common cause of error) that you understand the difference between a relative URL and an absolute/full URL. A relative URL is the location of the document within the web site, and does not include the actual domain name of the web site. These are used for documents held within the web site to simplify and shorten the URL. A absolute or full URL is one which includes the full domain name.
For example, for a absolute/full URL, ' http://www.yourdomain.com /directory/file.html'. the relative URL for this document would be, '/directory/file.html'.
Disable directory listings
Preventing directory listings can be very useful if for example, you have a directory containing important '.zip' archive files or to prevent viewing of your image directories. Alternatively it can also be useful to enable directory listings if they are not available on your server, for example if you wish to display directory listings of your important '.zip' files.
To prevent directory listings, create a .htaccess file following the main instructions and guidance which includes the following text:
IndexIgnore *
The above lines tell the Apache Web Server to prevent directory listings of directories and files within the directory containing the .htaccess file. The '*' represents a wildcard, this means it will not display any files. It is possible to prevent listings of only certain file types, so for example you can show listings of '.html' files but not your '.zip' files.
To prevent listing '.zip' files, create a .htaccess file following the main instructions and guidance which includes the following text:
IndexIgnore *.zip
The above line tells the Apache Web Server to list all files except those that end with '.zip'.
To prevent listing multiple file types, create a .htaccess file following the main instructions and guidance which includes the following text:
IndexIgnore *.zip *.jpg *.gif
The above line tells the Apache Web Server to list all files except those that end with '.zip', '.jpg' or '.gif'.
Alternatively, if your server does not allow directory listings and you would like to enable them, create a .htaccess file following the main instructions and guidance which includes the following text:
Options +Indexes
The above line tells the Apache Web Server to enable directory listing within the directory containing this .htaccess file. You can also reverse this to disable directory listings by replacing the plus sign before the text 'Indexes' with a minus sign. e.g. 'Options -Indexes'.
You can also include a default description for the directory listings that is displayed at the top of the page by placing a file called 'HEADER' in the same directory. The contents of this file are displayed before the list of directory contents. You can also include a footer, by creating a file called 'README'. The contents of this file are displayed after the list of directory contents.
Demo
Enable Directory Browsing
Options +Indexes
## block a few types of files from showing
IndexIgnore *.wmv *.mp4 *.avi
Disable Directory Browsing
Options All -Indexes
Customize Error Messages
ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.html
Get SSI working with HTML/SHTML
AddType text/html .html
AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
# AddHandler server-parsed .htm
Change Default Page (order is followed!)
DirectoryIndex myhome.htm index.htm index.php
Block Users from accessing the site
<limit GET POST PUT>
order deny,allow
deny from 202.54.122.33
deny from 8.70.44.53
deny from .spammers.com
allow from all
</limit>
Allow only LAN users
order deny,allow
deny from all
allow from 192.168.0.0/24
Redirect Visitors to New Page/Directory
Redirect oldpage.html http://www.domainname.com/newpage.html
Redirect /olddir http://www.domainname.com/newdir/
Block site from specific referrers
RewriteEngine on
RewriteCond %{HTTP_REFERER} site-to-block\.com [NC]
RewriteCond %{HTTP_REFERER} site-to-block-2\.com [NC]
RewriteRule .* - [F]
Block Hot Linking/Bandwidth hogging
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
Want to show a “Stealing is Bad” message too?
Add this below the Hot Link Blocking code:
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/dontsteal.gif [R,L]
Stop .htaccess (or any other file) from being viewed
<files file-name>
order allow,deny
deny from all
</files>
Avoid the 500 Error
# Avoid 500 error by passing charset
AddDefaultCharset utf-8
Grant CGI Access in a directory
Options +ExecCGI
AddHandler cgi-script cgi pl
# To enable all scripts in a directory use the following
# SetHandler cgi-script
Posted in: website seo | Tags: php htaccess introduction intro apache troubleshooting cgi redirects disable directory listing indexignore zip errordocument authtype require addhandler enable directory browsing ssi customize error messages change default page block hot linking bandwidth hogging block site 500 error grant Expression Web SuperPreview
To do compatibility testing of a web page I usually have to fire up a VPC and access the page from a browser instance inside that VPC (one VPC for IE6, another one for IE7, etc.)
How many times have you had to debug your web pages on virtual or multiple machines running different versions of Internet Explorer? Or had to wait for a slow web service to return renderings of your pages?
You don't have to do that anymore. Now you can debug your pages on multiple versions of IE on the same machine that you use for Web development.
Expression Web SuperPreview for Windows Internet Explorer is a stand-alone visual debugging tool that makes it faster and easier to migrate your sites from IE6 to IE7 or IE8. With SuperPreview, you can ensure that your Web sites work correctly in IE8 while also maintaining compatibility with earlier versions of IE.
SuperPreview shows your web pages rendered in IE6 and either IE7 or IE8, depending on which version you have installed on your machine. You can view the pages side by side or as an onion-skin overlay and use rulers, guides and zoom/pan tools to precisely identify differences in layout. You can even compare your page comp to how the targeted browsers render the page.
To help you quickly identify problem elements, DOM highlighting shows absolute positions of the rendered elements and HTML elements display CSS properties.
And perhaps what I think is the coolest feature, an overlay mode to compare exactly what’s different for pixel-perfect alignment. Or if you cross your eyes, the web in 3D.
Finally, how you can get your dirty web developer paws on this awesome tool, and it’s a little complicated to say the least. The beta of this software available right now is downloadable from Microsoft.com (250MB). The catch being it only supports renderings between IE6 and versions of IE installed on your computer already, but it should ease the pain of testing for IE6/7/8 compatibility for a lot of devs.
The full and final version of this product will be bundled together with Expression Web 3, sometime later this year and will run as a separate standalone application. Unfortunately for the many Mac web developers out there, because Expression Web is not an application part of the Expression Mac suite, SuperPreview will not be available.
Posted in: website seo General asp.net | Tags: expression web superpreview expression superpreview expression superpreviewWhat is an ISP (Internet Service Provider)
An ISP, or Internet Service Provider, is a company that offers internet access to individuals and businesses for a monthly or yearly fees. In addition to internet connection, ISPs may also provide related services like web site hosting and development, email hosting, domain name registration etc.
Different ISPs, and sometimes even the same one, offer different types of internet connections - dialup, cable and DSL broadband. Hardware such as dialup modem or a wireless modem and router are usually provided by the company. When you register with an ISP for its services, an account is created and you are provided with the login details –username and password. You connect to the internet via your account and this way the company keeps a watch on your online activities. All providers have strict terms of use and ensure you read these carefully before you sign up though, I believe, the casual web surfer would probably never be in breach of the contract. Any ISP, worth its salt, will also give you an email address, typically, based on your username – you can choose to use this email account or ignore it completely (not recommended).
ISPs can be both regional, confined to a geographic area, or national, servicing the entire country and they are connected with each other through Network Access Points (NAPs). ISPs are also referred to as Internet Access Providers.
Types of internet access
Most ISPs offer several types of internet access which essentially differ in connection speeds – the time taken for download and upload. Many also offer different plans or “packages” that vary in the download limit, number of email accounts on offer etc.
Dialup internet access is probably the slowest connection and requires you to connect to the internet via your phone line by dialling a number specified by the ISP. This means, dialup connections are not “always on”, unless you want to raise a huge phone bill, you would sever the connection when you finish work online.
Cable internet access can be obtained from the local cable TV operator. However, ask them for a demo first or check with your neighbours on the quality of service.
Internet access via DSL broadband is indeed very fast and ISPs can offer different download speeds – quicker the speed, higher will be the price. If you are planning for a DSL internet connection, ask the ISP if they would also install a wireless modem and router at your location. A wireless internet connection gives you freedom and flexibility – you need not be confined to one place (the work table, for instance) and can access the internet from any spot (even the bathroom) as long as your computer can catch the wireless signal. However, ensure that the provider secures the wireless connection with a password.
In many countries, especially those in which internet is still a kind of luxury, the ISPs may put a limit on the amount of data exchanged over a connection. For example, one may be allowed only a few GB (gigabytes) of download and upload each month. This is usually sufficient for routine users but if you plan to download movies and music or other large files, you have to keep a check on the amount of the data transfer.
Posted in: website seo General | Tags: isp internet service provider internet access differ internet dsl