• Home
  • Hosting
  • Search
  • Member List
  • Calendar
  • Help

 

Current time: 03-12-2010, 02:47 PM Hello There, Guest! (Login — Register)


Space Socket Community / Design and Development / Tutorials / Editing .htaccess:

100MB Hosting with Free Domain
Cpanel hosting & domain for $19.95/yr.
Cpanel Free Hosting Packages
upto 1GB space with PHP/ASP/Perl/Ruby & MySQL
1month free trail hosting
no payment for 1st month, choose any monthly or yearly plan afterwards

Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode | Linear Mode
Editing .htaccess:
10-06-2008, 06:34 AM
Post: #1
Hosam Offline
Member
***
Posts: 209
Joined: Jun 2008
Reputation: 2
Editing .htaccess:
Before letting you know how to edit a .htaccess file, it is important to define what .htacess is and the purpose it serves. .htaccess is a file extension, not a file. An htacess file is simply a text file in ASCII mode, containing Apache directives provided by the Apache web servers to execute commands for controlling a website.
Creating a file with .htacess extension is very easy – open up a text editor like Notepad or SimpleText, write the command and save that page as .htaccess.
.htaccess is an abbreviation for Hypertext Access; the default name for Apache's directory-level configuration file, which enables customizing the configuration directives i.e. the parameters defined in the main configuration file. However, the configuration directives need to be in .htaccess context and the user needs appropriate permissions to edit the file. The directives apply to the documents in all the directories and the subdirectories where the .htaccess file remains located. However, the other .htaccess files in the subdirectories may alter or nullify the effects of the ones in the parent directories.
While editing a .htaccess file, the first thing a person needs to be careful about is - to stay careful throughout the process. A small mistake is enough to render the website non-functional; therefore, the site should be immediately tested.

Edit a .htacess file with any text editing software
Any text editing software is sufficient to create or modify the .htaccess files; the first rule-of-thumb being to keep all the commands in a .htaccess file placed on a single line. This can be achieved by disabling the word-wrap feature of the text editor. In case the text editor or the operating system does not allow saving files with the .htaccess extension, the alternative is to save the file as .htaccess.txt before uploading it to the server. At certain times, it is also needed to CHMOD the htaccess file to 644 or (RW-R--R--). This serves a two-way purpose: for making the file usable by the server and to prevent it from being read by a browser. The FTP client should be used then for renaming the file to its proper name (.htaccess). It is also advised to upload the .htaccess files in ASCII mode, and not in BINARY. To hide the inner content of the file, the following code is inserted:
<Files .htaccess>
order allow,deny
deny from all
</Files>

The following are the examples of how a .htaccess file should be edited.

Editing .htaccess for redirecting to Files/Directories:
A major website overhaul often involves renaming large number of web pages. If these pages were been indexed by search engines and/or book-marked by users, the only solution is a redirect meta tag on the head of the old pages. This shall redirect the users to the new pages, but if a search engine fails to do so, then .htaccess is the last straw. The following command line:
Redirect permanent /oldfile.html Register a Domain, Find Hosting and Create a Website at Domain.com
can be repeated for each file that needs to be redirected. The directory name must be included if the file is placed elsewhere than the root directory.
Benefits:
An added advantage to prevent the increasing problem of link rot; it helps in letting functioning links stay functional even if the location is changed.

Changing the Default Directory Page:
The default directory page is usually named as index.htm or index.html, and many servers allow a range of pages called index (with multiple extensions) to be the default page. But .htaccess even makes possible something as weird as x.html or y.html to be the directory home page. Putting in

Directory Index x.html
in the .htaccess file for that directory would give the results. The command can also be used to specify alternatives, in case the first filename doesn’t exist. It should come like this:

* Directory Index index.html index.htm x.html y.html


Allowing and Preventing Directory Access:
Though by default configuration most of the servers block outsiders from browsing the parent directory, certain servers do not provide this facility and allow unauthorized access. There are ways to prevent it; a simple command line in the .htaccess file is all that’s required.

IndexIgnore */*

In case you want to override the servers settings regarding stopping of unauthorized access, write the following in the command line of your .htaccess file.

Options +Indexes:

Allowing SSI in .html files:
Servers, mostly analyze syntactically (parse) files with a .shtml extension for Server Side Includes (SSI). In case this extension needs to be excluded or if it becomes a priority to retain the .htm or .html extensions used by files prior to a change, adding the following commands to .htaccess file can solve the problem.

AddType text/html .html
AddHandler server-parsed .html
AddHandler server-parsed .htm

It is also recommended if SSI is being used for the first time.
However, this shall significantly, and unnecessarily, slow down the loading of pages.

Blocking Intrusion or unauthorized access to a website:
.htaccess brings the option to stop certain IP addresses from accessing a particular site; it is possible to ban a single IP address as well. To do that type in the following lines:

order allow,deny
deny from 123.456.78.90
deny from 123.456.78
deny from .aol.com
allow from all

The banned users shall get a 403 error – “You do not have permission to access this site”.

Preventing Linking to the Images of a website:
It has been observed that some websites want to link to the images of your site but they don’t want to download the images (to save their disk space). By doing this, they get your images but you lose your bandwidth. You can prevent people doing this by inserting a few lines of command in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourdomainname.com/.*$ [NC]
RewriteRule .(gif|jpg)$ - [F]

Stopping the Email address collectors:
It is important to let certain robot visitors from other search engines visit your website. However, there are other malevolent robots that need to be kept at bay, especially those ones that collect e-mail addresses and add them to spam mail lists. Just write the following lines in your .htaccess file to stop these email address collectors.

RewriteCond %{HTTP_USER_AGENT} A [OR]
RewriteCond %{HTTP_USER_AGENT} B [OR]
RewriteCond %{HTTP_USER_AGENT} C [OR]
RewriteCond %{HTTP_USER_AGENT} D [OR]
RewriteCond %{HTTP_USER_AGENT} E [OR]
RewriteCond %{HTTP_USER_AGENT} F
RewriteRule ^.*$ X.html [L]

A, B, C etc. are the name of the robots and must be followed by '[OR]' – The last name won’t require it. Though the program is by no means a foolproof one and many of the robots do not identify themselves. Moreover, creating an exhaustive list of those that do identify themselves is a mammoth of a task. But the program works fine with the known ones.
Note:

* One of the negative sides of the .htaccess files is they can slow down servers considerably.
* .htaccess files help in user authentication, if they are configured manually to control access to directories on a particular website. It can be done from the Shared Hosting control panel; else, there are numerous Perl scripts that allow setting up full user management systems.

important points to remember:
Apache 1.3.1 demands the methods listed in <Limit> directives should be in uppercase. Method names, such as GET, POST, and PUT are case-sensitive. Formerly, the <Limit> directive parser incorrectly treated both of these as being the same. But Apache 1.3.1 has a built-in method for limit processing, which only understands uppercase method names. Therefore, if something like "<Limit Get post>" exists as a clause in the configuration files, it needs to be corrected to uppercase.
If there are unrecognized method names in the server configuration files, the result will be the server logging an error message and failing to start. htaccess files, upon confronting an unknown method shall cause the server to log an error to its error log and return an 'Internal Server Error' page to the client.
after all please stick this thread its helps huge amount of your users here and helping general users from another Shared Hosting servers.

Syrian Window
http://syrianwindow.com
try to update with great design and content try it please! Cool
Visit this user's website Find all posts by this user
Quote this message in a reply
10-06-2008, 12:52 PM
Post: #2
Clepto Offline
Junior Member
**
Posts: 40
Joined: Dec 2007
Reputation: 0
RE: Editing .htaccess:
good article, I appreciate it.
Find all posts by this user
Quote this message in a reply
10-07-2008, 10:27 PM
Post: #3
Death Offline
Member
***
Posts: 216
Joined: Aug 2008
Reputation: 2
RE: Editing .htaccess:
Good information!
thanks for sharing Smile
Find all posts by this user
Quote this message in a reply
12-09-2008, 01:33 AM
Post: #4
evoreb Offline
Junior Member
**
Posts: 8
Joined: Dec 2008
Reputation: 0
RE: Editing .htaccess:
thanks for the article...
Find all posts by this user
Quote this message in a reply
11-21-2009, 09:53 PM
Post: #5
alish Offline
Junior Member
**
Posts: 27
Joined: Nov 2009
Reputation: 0
RE: Editing .htaccess:
Perfect..!!! Thank you very much..!!
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
Forum Jump:


Contact Us | Space Socket | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication

Powered By MyBB, © 2002-2010 MyBB Group.
CoolLime - Designed by MyBBThemes