468

I want to create a .htaccess file manually and discovered it seems impossible through the Windows UI. I get a "you must type a filename." message. There has to be a way to create files with . as a prefix in Windows.

Can this be done manually?

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Doug Chamberlain
  • 11,192
  • 9
  • 51
  • 91
  • 4
    possible duplicate of [how to allow files starting with period and no extension in windows 2003 server?](http://stackoverflow.com/questions/19442/how-to-allow-files-starting-with-period-and-no-extension-in-windows-2003-server) – David Heffernan Feb 15 '11 at 15:46
  • 2
    that's because it is off topic. –  Feb 15 '11 at 19:55
  • 5
    @Will Is there some other place a other questions like this would belong? I noticed you closed both, but judging by the response and views on both questions, it would seem there is at least some interest in questions of this nature. – Doug Chamberlain Feb 15 '11 at 20:27
  • 1
    the other one is "grandfathered", so to speak. I closed so people won't be tempted to add more answers. If I had seen this earlier, I would have migrated it to [SuperUser](http://superuser.com), our sister site for questions just like this one. Since you already accepted an answer I hesitate to migrate.... –  Feb 15 '11 at 20:50
  • 1
    In case anyone comes here looking for the equivalent for directories, `mkdir .ssh` e.g. works fine from the command line. – javawizard Mar 05 '14 at 01:34
  • 46
    I had run into this before and knew there was an easy answer. I was surprised not to find it here. So, I did some more searching and found it elsewhere. I can't "answer" because the question is closed so here it is: just put an extra dot AFTER the file. Windows will drop it. `.this.` => `.this` – TecBrat Jul 16 '14 at 17:10
  • 10
    Please someone think about casting reopen vote on this. In my opinion, this is not off topic, as the Windows Explorer is a tool used by many developers, specially when new in the craft. Creating a `.htaccess` is a common problem for beginners or hobby web developers. And: this problem bugged me for years, most workarounds are anoying as hell (call `cmd` ...) and there is a better way (thanks @TecBrat). Google gave me this page as top hit for "windows create file starting with dot", so the answer should be here of all places (as an answer with good score!) – kratenko Aug 08 '14 at 14:50
  • 3
    @kratenko I flagged it to re-open. (not enough rep to do it myself) The moderator replied "declined - Windows Explorer is not primarily used as a programming tool." – TecBrat Sep 27 '14 at 01:48
  • 2
    That moderator sure must be close minded. -pun intended- – Doug Chamberlain Jan 07 '15 at 21:25
  • 5
    I attempted to re-open it. I needed this to add a Git .ignore file. This can be a programming-related question; it's not simply a "how do I use Explorer" question. – james.garriss Jun 03 '15 at 16:04
  • 2
    [How do I rename a file to .htaccess in Windows 7?](https://superuser.com/q/56562/241386) – phuclv Mar 31 '17 at 15:52
  • This post can be safely migrated to superuser as it has very good answers. Please see this very similar question - [Create/rename a file/folder that begins with a dot in Windows?](https://superuser.com/q/64471/374397) – RBT Mar 22 '19 at 06:06
  • Note that as of Windows 10 version 1903, released first half 2019, Windows is able to create such files directly (such as in, e.g., Windows/File Explorer), without requiring any workarounds such as trailing periods or using Notepad. – Justin Time - Reinstate Monica Jul 27 '20 at 19:50

17 Answers17

372

If you start Notepad and then File -> Save As -> Write .htaccess and choose "All Files" as the type - then it will create the .htaccess file for you.

Notepad save as .htaccess

Boann
  • 48,794
  • 16
  • 117
  • 146
foens
  • 8,642
  • 2
  • 36
  • 48
307

Windows 7, 8 & 10

This is dead easy since Windows 7. In File Explorer, right click anywhere and create a new file. Type the new filename as .something. (notice the appended period) and press enter twice, job done.

Demonstrating how to create a file with no name in File Explorer.

So instead of being prompted with

You must type a file name.

You will instead be prompted with

If you change a file name extension, the file might become unusable.

Note: If you're having issues then please ensure you have "file name extensions" visible, you can activate this under the "View" menu in File Explorer. Also, this method works for folders too.

Matt Kieran
  • 4,174
  • 1
  • 17
  • 17
89

Within Notepad select File > Save As...

File name: ".whatever you want" (with the leading dot)

You can do it in Explorer (in Windows 7) by adding a period at the end of the filename:

.whatever you want.

Windows will automatically remove the trailing dot when you validate.

kiwibonga
  • 587
  • 4
  • 13
dhirschl
  • 2,088
  • 13
  • 18
30

Go to command prompt, cd to the appropriate folder and type:

notepad .htaccess

After confirmation dialog the file will be created and you will be editing it directly. If you just want to create an empty file, try

echo. > .htaccess
Boocko
  • 731
  • 5
  • 16
11

You could also use Command Prompt with move: move x.extension .extension

Damian Yerrick
  • 4,602
  • 2
  • 26
  • 64
Nikoloff
  • 4,050
  • 1
  • 17
  • 19
  • 1
    DOS (COMMAND.COM, 16-bit) is not part of Windows since Windows ME. It's CMD.EXE, 32-bit, which happens to support MS-DOS commands. – Alan B Nov 12 '15 at 12:19
  • yes [DOS and Windows cmd are very different things](https://superuser.com/q/451432/241386) – phuclv Mar 31 '17 at 15:54
9

Just type .htaccess. as filename. Notice the dot at the end of htaccess. This will change in Windows to .htaccess without a dot at the end.

Philippe
  • 28,207
  • 6
  • 54
  • 78
Jacky
  • 91
  • 1
  • 1
9

You can do this in any program other than Explorer, e.g. Notepad, cmd.exe etc.

You just can't do it in Explorer, and Raymond Chen has offered an explanation as to why not.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
5

Even if you don't have any third party editor (Notepad++ etc.) then also you can create files with dot as prefix.

To create .htaccess file, first create htaccess.txt file with Context Menu > New Text Document.

Then press Alt + D (Windows 7) and Ctrl + C to copy the path from the Address bar of Windows Explorer.

Then go to command line and type code as below to rename your file:

rename C:\path\to\htaccess.txt .htaccess

Now you have a blank .htaccess without opening it in any editor.

Hope this helps you out.

Vicky Dev
  • 1,893
  • 2
  • 27
  • 62
5

You can save it using the Save As dialog using ".something".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sachin Shanbhag
  • 54,530
  • 11
  • 89
  • 103
4

Use something like Notepad++ (or even Notepad), 'Save As', and enter the name .htaccess that way. I always found it weird, but it lets you do it from a program!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brian
  • 8,418
  • 2
  • 25
  • 32
3

Might sound unbelivable, but Windows 1903 finally allows to name files in Explorer with a leading dot :-)

debuglevel
  • 434
  • 5
  • 10
2

In Windows, just go to the folder using cmd and type the following command:

DIR>.htaccess

This command will create a .htaccess file and will dump some data in it. Remove the data, and it can be used as .htaccess file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eugine Joseph
  • 1,552
  • 3
  • 18
  • 40
  • 3
    A simpler command would be `echo "" > .htaccess`, this way you don't have to clear any data. – DFSFOT Jan 14 '19 at 14:06
2

It seems that Microsoft finally is addressing this problem. Current versions in the Insider Editions of Explorer allows creating files with a dot at the front.

Tested with Build 19541

theking2
  • 2,174
  • 1
  • 27
  • 36
0

As an addition, if have Sublime Text installed in your development computer, you can drag the file to your opened Sublime Text window, right click the filename -> rename and enter whatever name even without any extension. This worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Diego Ponciano
  • 453
  • 5
  • 12
0

If you use Git and have Git Bash installed you can open a Git Bash at the directory (via Right Click in the white space in Explorer > Git Bash Here) and do:

touch .htaccess
gpresland
  • 1,690
  • 2
  • 20
  • 31
0

You can use echo. > .gitignore. This is how I achieved it to create .gitignore:

C:\Users\jaimemontoya\[path]>dir
 Volume in drive C is OS
 Volume Serial Number is 2BD2-JQ68

 Directory of C:\Users\jaimejaimemontoya\[path]

11/02/2021  02:42 AM    <DIR>          .
11/02/2021  02:42 AM    <DIR>          ..
11/05/2021  05:22 AM    <DIR>          .git
11/02/2021  02:41 AM    <DIR>          .gradle
11/02/2021  02:43 AM    <DIR>          .idea
11/02/2021  02:41 AM    <DIR>          app
11/02/2021  02:41 AM    <DIR>          build
..........
..........
              12 File(s)         14,104 bytes
               8 Dir(s)  231,501,361,152 bytes free
               
C:\Users\jaimemontoya\[path]>echo. > .gitignore

C:\Users\jaimemontoya\[path]>dir
 Volume in drive C is OS
 Volume Serial Number is 2BD2-JQ68

 Directory of C:\Users\jaimemontoya\[path]

11/05/2021  05:40 AM    <DIR>          .
11/05/2021  05:40 AM    <DIR>          ..
11/05/2021  05:22 AM    <DIR>          .git
11/05/2021  05:40 AM                 3 .gitignore
11/02/2021  02:41 AM    <DIR>          .gradle
11/02/2021  02:43 AM    <DIR>          .idea
11/02/2021  02:41 AM    <DIR>          app
11/02/2021  02:41 AM    <DIR>          build
..........
..........    
              13 File(s)         14,107 bytes
               8 Dir(s)  231,512,551,424 bytes free 
Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
-2

in windows, you can also use cmd to create these type of file.

  1. run cmd
  2. goto directory where you want to create this folder
  3. type mkdir .htacess

Please verify if this file is created or not.

  • `.htaccess` (spelled with two `c`s) should not be a directory or a folder. It should be a text file. There are ways to create an empty file in Windows CLI, see [Create an empty file on the commandline in windows (like the linux touch command)](https://stackoverflow.com/questions/30011267/create-an-empty-file-on-the-commandline-in-windows-like-the-linux-touch-command) – Stephen Ostermiller Sep 28 '22 at 09:32