[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How does .htaccess file work?

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

Thank you,
0
Comment
Question by:Aiysha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
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…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

649 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