?
Solved

How does .htaccess file work?

Posted on 2006-11-15
3
Medium Priority
?
290 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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

801 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