You should avoid using.htaccess files completely if you have access to httpd main server config file. Using.htaccess files slows down your Apache http server. .htaccess file is a powerful and ancient Apache Server configuration file for doing SEO 301 Redirects & Rewrites. This is the ultimate htaccess howto.
Various . htaccess samples and tutorials"Many people have only taken the . There is a lot more to what can be done with an . The . htaccess file is a normal file that you can edit in programs such as Notepad, just as simple as editing your everyday documents. A file on Windows consists of a filename and an extension, such as document. Windows doesn't allow files with an extension and no filename. However, on UNIX, you can call a file whatever you want, extension or no extension. Warning. Although using .
Apache Docs Tutorial.htaccess files Apache Docs: List of available Directives Apache Docs Tutorial: mod_rewrite Reference Apache Wiki: Various configuration recipes From the.htaccess cheatsheet.
The Ultimate Guide to.htaccess Files. by Joseph Pecoraro. Difficulty: Intermediate Languages: Web Development.htaccess. Apache's. In any event, you can always give it a shot and see if a simple.htaccess file works! Included in this tutorial’s sample download are two ways which you can check to see if.htaccess. 7 htaccess file examples that work for SEO. Lee Kane. SEO tips & tricks. 28. With the htaccess file and all the other modifications made within my websites pages as directed by SEOquake. I like this article with simple step by step guide on htaccess file!!! SLB. October 19, 2015 at 7:29 am. Reply. Great Article. Clear all of my confusion about htaccess. Well done. Brian.
Microsoft Front. Page Extensions. The Front. Page extensions use the .
If you do want to (this is not recommended, but possible) you should download the . Creating the . htaccess File. To create a . htaccess file on Windows, just open a new document in Notepad and save it as . All files is selected in the Save as type drop- down menu so it doesn't save it as . When you go to upload an . ASCII, never BINARY since it is a text file. While . htaccess files will work just by uploading them, we recommend that you CHMOD the .
RW- R- -R- -). This makes the file readable by your web server, but at the same time, disables browsers from reading it. If your . htaccess file can be read by anyone, you're security is in big trouble.
When you create an . If you don't, your text editor might add characters to the file that will cause problems with the Web server which will result in a non- functional . Also make sure that all of your commands in an . If you don't you will end up with an .
When you use a . htaccess file on your web server, the file affects the current directory and any of it's sub- directories. If you place an .
Custom Error Pages. Custom error pages enable you to customize the pages that are displayed when an error occurs.
Not only will they make your website seem a lot more professional, but they can also save you some visitors. If a visitor sees a generic error page, they are likely to leave your site. However, if they see a helpful error page, they might just stay at your site because they can just click on a link to go to another page within your site. You can create error pages for all error codes, however many webmasters only make error pages for the 4 most common errors, which are: Error 4. Authorization Required.
Error 4. 03 - Forbidden. Error 4. 04 - Not Found. Error 5. 00 - Internal Server Error. To specify what the server should do when an error is found on your website, enter the following into an . Error. Document < Error.
Code> /home/LOGIN/public_html/error- document. Change < Error. Code> to the code of the error. Also, change the path to the error document. Simply repeat the above line of code for all other errors. Once the file is uploaded, your visitors will be directed to the page that you specified. Here's a sample .
Error. Document enabled. Error. Document 4.
Error. Document 4. Error. Document 4. Error. Document 5. You can use full URL's for the path to your error documents on all error codes except 4. Also, instead of specifying a URL for an error code, you can display a message too.
Here's an example: Error. Document 4. 04 "< p> < strong> Sorry, the document you requested could not be found.< /strong> < /p> "This is quite useful if you only need to display a short message because it saves you having to create additional files. As you can see, you can use normal HTML code. Here's another . htaccess file with Error. Document enabled.
This time, we are displaying messages instead of going to a different URL. Error. Document 4. Error 4. 01< /p> < p> Authorization Required.< /p> "Error. Document 4. 03 "< p> Error 4. Forbidden.< /p> "Error. Document 4. 04 "< p> Error 4.
Not Found.< /p> "Error. Document 5. 00 "< p> Error 5. Internal Server. Error.< /p> ".
Limit the Number of Concurrent Visitors to your Website. If you need to limit the amount of concurrent visitors to your website, this can be easily set up. Open a program such as Notepad and insert the following line of code: Max. Clients < Number of max clients> Change < Number of max clients> to the maximum number of clients you want to allow access to your website. Disable Directory Listings.
Occasionally, you may not have a default index document in a directory. If a default document is not found, whenever a visitor types in the directory name in their browser, a full listing of all the files in that directory will be displayed. This could be a security risk for your site. To prevent without having to add a default index document to every folder, you can enter the following line in your . Options - Indexes.
IP Addresses"> Deny/Allow Certain IP Addresses. If you have problems with certain visitors to your website, you can easily ban them. There are two different ways to ban visitors.
This can be done using their IP address or with the domain name which they came from. Here's an example showing you how to deny a user by their IP address. The above code will deny the 2. IP address and allow everyone else to enter. If you want to deny a block of IP addresses, use this code: order allow,denydeny from 2. The above code will deny the 2. IP address, the 2.
IP address and all the way up to 2. IP addresses. Here's an example showing you how to deny a user by the domain name from which they came from. The above code will deny anyone coming from www. Here's an example showing you how to deny a user from a domain name and all subdomains within the domain name. The above code will deny anyone coming from www.
Order deny,allow. Deny from all. Allow from youripaddress.
The above code will block all visitors from accessing your site except for yourself if you replace youripaddress with the IP address that was assigned to you by your ISP. Deny Access To a Folder During a Specific Time. If for some reason you would like to block access to files in a directory during a specific time of day, you can do so by adding the following code to an .
Rewrite. Engine On# If the hour is 1. PM)Rewrite. Cond %{TIME_HOUR} ^1. Then deny all access. Rewrite. Rule ^.*$ - [F,L]# Multiple hour blocks# If the hour is 4 PM or 5 PM or 8 AMRewrite. Cond %{TIME_HOUR} ^1.
Alternative Index Files. When a visitor accesses your website, the server checks the folder for an index file. Some examples of common index files are: index. The supported index files depend on the how the server is set up. If the server cannot find an index file, it will try to display an index of all the files within the current directory, however if this is disabled, the server will end up displaying a 4. Using . htaccess, you can use a completely different index file instead of the defaults listed above. To do this, insert the following line into an .
Directory. Index pagename. Change pagename. html to the page that you would like to use as the index file. Redirection. Using Redirect in an . For example if you use index. Redirect works by typing: Redirect /home/LOGIN/public_html/path/to/old/file/old. The first path to the old file must be a local UNIX path. The second path to the new file can be a local UNIX path, but can also be a full URL to link to a page on a different server.
Here are a few examples of some redirects: Redirect / /new/Redirect /index. Redirect /private/ http: //www. Redirect /img/logo. Protect Your . htaccess File. When a visitor tries to obtain access to your .
However, you can apply a bit more security to your . Files . htaccess> order allow,denydeny from all< /Files>. If you would like to redirect anything from http: //domain. URL), you can accomplish this by using the code below. This is helpful in search engine optimization and will help give your site a higher page rank. Rewrite. Engine On.
Rewrite. Cond %{HTTP_HOST} !^www\.* [NC]Rewrite. Rule ^(.*) http: //www.%{HTTP_HOST}/$1 [R=3.
Prevent Image Hot Linking. Hot linking or bandwidth stealing is a common problem. It happens when people link to files and images on a different server, display them on their website and the bandwidth is at the other person's expense. By entering the lines below, you can prevent hot linking to your website.
Rewrite. Engine On. Rewrite. Cond %{HTTP_REFERER} !^$Rewrite. Cond %{HTTP_REFERER} !^http: //(www\.)?
NC]Rewrite. Rule \.(gif|jpg)$ http: //www. R,L]. Change yourdomain. On the last line of code, change hotlink. Force Text Files to Download and Not Show in Your Browser. By default, if a text file (. This is because the default MIME type for . You can however change this by adding the line below: Add.
Type application/octet- stream txt. Be warned though, every . If you only need to target a specific file, use this code. Files yourfile. txt> Add. Type application/octet- stream txt< /Files>. Email Address"> Specify the Server Administrators Email Address. When users on your website encounter an error, a page is displayed with details about the error and the server administrator's email address is displayed.
To modify the server administrator's email address insert the following code: Server. Admin admin@yourdomain. Be sure to change admin@yourdomain.
Specify a Custom Error Log. The Error. Log feature allows you to specify the local UNIX path to store your server error logs. These logs contain errors that visitors have encountered on your website. To specify a custom error log on your account, insert the following code: Error. Log /logs/error_log. You can change the path and filename of the error log, but your path must start with a forward slash.
Enable Password Protection. Password protection is probably the most popular feature of htaccess and is used all over the Internet. The reason why it is so popular is because it is very simple to set up and is the strongest form of protection which cannot be bypassed.
When you set up password protection, you need to set up the password protection options in a . First, we are going to set up the usernames and passwords inside the . The passwords inside a . Once you have created the required usernames and passwords, you need to place them inside a .