Solved

How does .htaccess file work?

Posted on 2006-11-15
3
288 Views
Last Modified: 2010-04-09
Please tell me how does the .htaccess files works.

Thank you,
0
Comment
Question by:Aiysha
3 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17951557
That's a wildly extensive topic.  Almost any piece of Apache configuration (there are certainly some exceptions) can go in a .htaccess file.  Google will find hundreds of decent tutorials on using them (the first result for ".htaccess" is here: http://www.javascriptkit.com/howto/htaccess.shtml )

Can you be a little more specific about what you want to know?
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17962082
One of the most common uses of .htaccess is to hold directives associated with the mod_rewrite module.
As VoteyDisciple points out, this is one of many "complex" topics.

For mod_rewrite, .htaccess is used to contain directives that are specific to the containing directory.

mod_rewrite is frequently used to simplify URI's (i.e., the portion of the URL after the hostname (and optional port number)).

For example, using mod_rewrite, a URL like:

http://hostname/mod/rewrite/tutorial/

can be transformed to the URL required by the back end:

http://hostname/some_file.php?name=mod_rewrite_tutorial 
0
 
LVL 5

Accepted Solution

by:
basiclife earned 500 total points
ID: 17972754
An example of a .htaccess I use:

Options +Indexes
ErrorDocument 404 /index.php?page=404%20Not%20Found
ErrorDocument 401 /index.php?page=401%20Authorisation%20Required
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
RewriteRule ^updatecheck/(.*)/(.*)  updatecheck.html?software=$1&ver=$2 [L]
RewriteRule ^openurl/(.*)             openurl.php?url=$1 [L]
RewriteRule ^([a-z]*).html?(.*)      index.php?page=$1&$2                   [L]
RewriteRule ^([a-z]*).html             index.php?page=$1 [L]

From top-down:
Allow indexes (let ppl browse direcotory contents)
Set which pages to redirect to if an HTTP 401 or 404 error occures
The rest is part of mod_rewrite...

It allows me to have a URL of
www.mydomain.com/contact.html that actually accesses www.mydomain.com/index.php?page=contact
as well as taking in some variables and passing them to an update check script and another one that opens URLs.

It hides half of what my code does and also makes my pages appear static (like Experts-Exchange! the page you're looking at isn't plain HTML).

static pages are indexed better by search engines. Google for example does not index dynamically generated pages.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question