Mac OS X doesn't allow to name files starting with a dot. How do I name the .htaccess file?

Apache.HtaccessFilenamesOsx Leopard

Apache Problem Overview


As mentioned in the title, Mac OS X doesn't allow me to name files starting with a dot ( . ). But, I need an .htaccess file. Or, better, how do I use an htaccess file in Mac OS X without giving it a name starting with a dot?

I am running Mac OS 10.5.8 and XAMPP 1.7.3.

Apache Solutions


Solution 1 - Apache

You can't do this with the Finder. Open Terminal.app (Applications -> Utilities -> Terminal), and type:

> cd /path/to/directory/containing/htaccess
> mv current_file_name .htaccess

Example (do not take directory names or initial filename literally, of course):

terminal screenshot

Solution 2 - Apache

You can create files that begin with a "." if you can view hidden files.

Enter the following commands to show hidden files:

defaults write com.apple.finder AppleShowAllFiles -bool YES
killall Finder

When you're done enter these commands to hide them again:

defaults write com.apple.finder AppleShowAllFiles -bool NO
killall Finder
   

Solution 3 - Apache

You need to be able to see invisible files first.

In finder press ++. –command + shift + dot– to toggle hidden files visibility.

Then just go to the folder where the file is and you'll see it there. You can now rename the file to start with a . if you want.

To create a new file you can do this in the terminal: touch .htaccess, once the terminal is at the right folder

Solution 4 - Apache

Use the terminal instead of Finder to rename it. Try mv.

Solution 5 - Apache

You can add an alias in your startup script file to make the command shorter. Usually this is .bashrc, .bash_login or .profile file in your home directory.

alias ondot='defaults write com.apple.finder AppleShowAllFiles -bool YES; killall Finder'
alias ofdot='defaults write com.apple.finder AppleShowAllFiles -bool NO; killall Finder'

Now you can just type ondot to show hidden files. and ofdot for hiding hidden files

Solution 6 - Apache

This works so far as it goes. But TextEdit automatically added .txt to the end of the filename so I ended up with .htaccess.txt

And files with names starting with . don't show up in folders in Finder. You only see it if you go back into Terminal and use ls -a. And if it can't be seen then it can't be uploaded to an online webserver.

Using Fetch as my FTP client, I found it has a function which enables me to create a simple text file directly on the server. This worked to create .htaccess where I really needed it.

Solution 7 - Apache

Since .htaccess files will not be viewable once you change the name with Terminal (without some annoying searching) it is simpler to just drag an empty text file into the directory of choice using FTP and then rename away. Both filename and extensions can be change/removed once inside FTP.

Solution 8 - Apache

Use Terminal.

  1. Open Terminal.

  2. Change Directory to source folder where you want to create the file

  • cd Desktop
  1. Create the file using touch
  • touch .htaccess
  1. Open the file in any text editor
  • atom .htaccess

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDiego FaveroView Question on Stackoverflow
Solution 1 - ApacheMatt BallView Answer on Stackoverflow
Solution 2 - ApacheArkhaicView Answer on Stackoverflow
Solution 3 - ApacheDaniel ReinaView Answer on Stackoverflow
Solution 4 - ApacheIgnacio Vazquez-AbramsView Answer on Stackoverflow
Solution 5 - ApacheBeaudinn GreveView Answer on Stackoverflow
Solution 6 - ApacheTony LAwView Answer on Stackoverflow
Solution 7 - ApacheCyberneticView Answer on Stackoverflow
Solution 8 - ApacheLawrenceView Answer on Stackoverflow