What is .htaccess file?
An .htaccess file controls how Apache interacts with your site. When an .htaccess file is placed in your domain’s directory, the .htaccess file is detected and executed by Apache. An .htaccess file is commonly used for the following:
- Denying specific IPs to your site
- Password protecting your site
- Redirecting specific pages
- Rewriting URLs
- Custom error pages
L-Shaped Clear Tempered Glass Top Computer Desk with Pull Out Keyboard Panel
How to create .htaccess file in Windows?
- Open a new document in Notepad.
- Save it with the name .htaccess and make sure ‘All files’ is selected in the ‘Save as type’ drop-down menu. Doing this ensures it doesn't save it with the .txt extension.
- When you upload an .htaccess file to your account using FTP, make sure that the data transfer mode is set to ASCII. Never use BINARY since it is a text file.
- Upload it to your site's directory (where your site files reside).
- In your FTP client, change the permissions on the file to 644 (RW-R--R--).
- This makes the file readable by your web server, but at the same time disables browsers from reading it.
- The public should never be able to read your .htaccess file.
- Make sure of this: * Make sure that your text editor has word wrap disabled. If you don't, your text editor might add characters to the file that will cause problems with the web server which results in a non-functional .htaccess file. * Make sure that all of your commands in the .htaccess file are on a separate line. * When you use an .htaccess file on your web server, the file affects the current directory and any of its subdirectories. So if you place an .htaccess file in the root directory of your website, it affects every directory on your website.
Viewing .htaccess files in Mac OS X
Because Mac OS X is based on BSD UNIX, it follows the UNIX convention of hiding all files whose names begin with '.' from view. While listing, creating, and editing such files is possible from Terminal (e.g., ls -a), such files and folders don't usually show up in the Mac GUI, including the Finder and Open dialog boxes. You can set the Finder to show invisible files in Terminal:
- Click ‘Go’ > ‘Utilities’ and open the Terminal app.
- Enter the following:
defaults write com.apple.finder AppleShowAllFiles YES ; killall Finder
- If you’re using Yosemite, run the following command instead:
defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall FinderAlternatively, you can edit and upload .htaccess files via UNIX software in Terminal, or use a different name such as "htaccess", and then rename the file to ".htaccess" after it has been uploaded to the site.
Finding .htaccess files in your FTP clientYour FTP client may suddenly refuse to display the file once you rename it to .htaccess. In order to display the .htaccess file, you need to allow the FTP client to show hidden files.
What do you use .htaccess file for?
You can use .htaccess file for an umber of reasons:
- Secure your website.
- Change your website php version.
- Allow/Deny access to your website.
- Setup part of your WP like multisite and etc.
- And many others.