You can make configuration changes on a per-directory basis by creating .htaccess files on an Apache server (although other server options do exist). The directives that you create within the .htaccess file will control the directory the file is placed within--place the file at the root level of the directory.
How to create an .htaccess file:
Like most any file type, you can create a file by renaming a simple text document and giving it the name ".access". However, Windows users may need to make changes to be able to view .htaccess files within their system, which is a simple configuration change to allow viewing of "hidden files." Dreamweaver may not recognize .htaccess files due to the fact that they are an unrecognized file extension by default. If you use Dreamweaver or a similar program to edit code, select to "open the file using Dreamweaver." Two programs that are great for editing .htaccess files are: NotePad or SimpleText. By default, Notepad it will save the file .htaccess.txt--so you will need to remove the .txt extension.
Note: .htaccess is the file extension. It is not file.htaccess or somepage.htaccess, it is just named .htaccess
General notes on .htaccess
Use .htaccess to password protect a directory
You can use .htaccess to password a directory on your server. There are numerous approaches to creating an authentication system. Htaccess can be used for passwords. Place the username and password in the htpasswd file.
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Directory To Be Protected"
Require valid-user
The full/path/to/.htpasswd should be the full path to the .htpasswd file. On Windows for instance, it could look like this: C:\wwwrootlevel\username\.htpasswd.
The above .htaccess file will password protect all files in the folder that it is placed in, including all sub-folders as well.
Use .htaccess to protect a single file
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Page"
<Files "mywebfile.html">
Require valid-user
</Files>
This script will password-protect just the mywebfile.html file in the folder where you put the .htaccess file.
Change your default directory page
You can specify a certain file to be your index file (directory index). By default, index.html or index.htm is often the default index for directories. Let's say you wanted to use a different file as your directory index, you could by using .htaccess to specify the file.
DirectoryIndex filename.html
Redirects using .htaccess
You can create redirects using .htaccess as well. For example, 301 permanent redirects are very important for SEO purposes since they let Google and other search engines know if a file has been moved and where to find this file.
Redirect /olddirectory/oldfile.html https://yoursite.com/newdirectory/newfile.html
by Jonathan Franchell, CEO of Ironpaper - For more tips and hacks: Need to remove a new line after h1 tags? Both web designers and SEO practitioners need to employ headline tags: H1, H2, H3 in several ways to improve web page structure and tag...
The Crowded Arena of the IT Marketplace Updated December 2024 The Information Technology (IT) landscape is experiencing rapid growth and intensifying competition. IT spending is projected to reach nearly 5.1 trillion U.S. dollars in 2024, a...
Updated December, 2024 The field of digital marketing is evolving rapidly in response to new technology and changing buyer expectations. To help career-minded marketers, we’ve rounded up the top 10 skills needed to succeed in the field. These are...