Solved

How does .htaccess file work?

Posted on 2006-11-15
3
284 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now