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?
This question is related to
windows
.htaccess
windows-xp
filenames
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.
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
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
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.
You could also use Command Prompt with move
: move x.extension .extension
You can save it using the Save As dialog using ".something".
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.
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.
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.
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.
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.
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.
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
Might sound unbelivable, but Windows 1903 finally allows to name files in Explorer with a leading dot :-)
Source: Stackoverflow.com