Create .htaccess files on OS X and Windows
This is a quick tutorial on how to create .htaccess files on Windows (PC) and OS X (Mac). This post also explains a bit about how .htaccess files work, and how to view them on various operating systems.
About .htaccess files
.htaccess files (or “distributed configuration files”) provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
By default .htaccess files are hidden on Windows and OS X, so you can’t just right-click and create a new .htaccess file. But it is certainly is possible, as explained in the following sections of this tutorial.
Note that if you just want to view .htaccess files (and don’t need to create them), you can simply enable your machine to show hidden files. Or use any FTP or code-editing software that is capable of displaying hidden files (it’s a common feature).
The easy way to create .htaccess files
The easy way to get an .htaccess file on your machine — whether Mac or Windows — is to just download a copy from a reliable source. In my book, The Tao of WordPress, I make it easy for readers to grab a copy of a blank .htaccess file directly from my server:
That’s gonna put an .htaccess file in your machine’s default download directory. Of course, .htaccess files are hidden by default, so jump ahead to either section to learn how to view them on either Windows or OS X.
Create .htaccess files on PC / Windows
Note that I no longer use Windows, so the screenshots here are from WinXP (which was the last version of Windows that I owned). So things may look or work a bit different depending on which version of Windows you’re using.
That said, here are the steps to create a new .htaccess
file on a Windows machine:
- Step 1: Open a new text file and add your .htaccess code
- Step 2: Select File > Save As..
- Step 3: In the “Save As” box, name the file “.htaccess”
- Step 4: In the “Save As” box, specify “All Files” for “Save as type”
- Step 5: You now have a new .htaccess file on your Windows machine
Note: .htaccess files are hidden by default, so to view the file you need to enable “Show hidden files” on your machine. The setting for this varies depending on your version of Windows, so refer to the manual if needed. Once you enable hidden-file display, .htaccess files should be visible.
Alternately, you should be able to view hidden files such as .htaccess using any decent FTP program or code editor.
Create .htaccess files on Mac / OS X
The process for OS X basically is the same as it is for Windows. Here are the steps (without screenshots):
- Open a new TextEdit file
- As you save the file, name it “.htaccess”
- A dialogue box will popup saying that “Names that begin with a dot are reserved for the system.” That’s fine, go ahead and click OK to use the dot.
- Done.
Like Windows, OS X considers file names that begin with a dot as system files, so they are not visible by default. To view them, you can use just about any good FTP program, or install an app that can display hidden files on your machine. There also are Terminal commands to display all hidden files. Try a search for keywords such as “show hidden files mac” or similar.
Bonus: Show/Hide Files via Terminal
Here are some commands for showing and hiding hidden files on Mac via Terminal:
Show hidden files
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
Hide hidden files
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder
That’s all folks, happy .htaccess’ing :)