Solved

How does .htaccess file work?

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hover Gone 16 30
FTP File permissions 1 30
Bootstrap Datable Spinner 3 30
(URGENT) Help HTML and CSS Resizing Images 2 20
Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
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…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

706 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