How do I rename a file to .htaccess in Windows 7?

62

18

I'm using XAMPP to test a PHP script. Now, in the root of the folder I want to place a .htaccess file according to the requirements of the script.

But Windows won't let me rename it to .htaccess. Is there any way to go around it?

I'm using Windows 7 RTM.

rzlines

Posted 2009-10-17T12:30:37.583

Reputation: 7 006

Answers

78

this link discusses the same problem on XP.

I'll let you read it and decide if it applies to Windows 7, but the solution involves using a command line.

EDIT:

It starts from the fact that Windows will let you create an htaccess.txt file
Then

Start Run > cmd

then type

rename c:\pathtoyourhtaccessfile\htaccess.txt .htaccess

will do the trick

pavium

Posted 2009-10-17T12:30:37.583

Reputation: 5 956

8LOL that's another weird issue caused by Windows! – Ahmad Alfy – 2011-09-25T08:27:40.280

85

Thanks to https://serverfault.com/questions/22626/rename-files-to-empty-filename-in-windows-vista I learned a new trick. Since this page shows up in Google higher for that error message, I thought I'd link it here too.

Essentially if you want to do it in Explorer, name it .htaccess. with a trailing dot. The trailing dot tells Windows what the extension should be, and the initial dot and letters tell it what the filename (without extension) should be. It appears that a file without an extension is permissible, but not one without a filename. Fortunately, a file without an extension requires no dot, so we get the deletion that creates the filename we wanted (which is just an extension - see the filetype that Windows reports?)

You can do this with any string, not just htaccess. It makes a little sense to me because files that start with a dot have special meaning.

Jay Paroline

Posted 2009-10-17T12:30:37.583

Reputation: 961

3it's a bug until someone finds a use for it then it's a feature... this is now officially a feature. :) – jx12345 – 2014-11-12T14:59:08.690

2Awesome, so you can just type .filename. and it becomes .filename – Daniel Little – 2014-12-04T05:09:50.150

1is this a bug or a feature? – etuardu – 2012-07-05T19:31:06.177

9

Don't create the file in Windows Explorer. Create it in whatever program you are using (notepad, vim, eclipse whatever). Then select "Save As" and make sure "All Files" is selected. Type in .htaccess . It should work.

The All Files is to prevent the program automatically adding a file type extension (e.g. .htaccess.txt)

Macha

Posted 2009-10-17T12:30:37.583

Reputation: 4 772

6

One thing you could do is use another file as the .htaccess file.

Open up the httpd.conf or whatever the XAMPP setup calls the Apache configuration file.

Look for the line that starts with AccessFileName and change the value at the end to something that Windows will allow you to save it as.

AccessFileName htaccess.txt

If you don't find that line, just add the above in.

Then restart your XAMPP.

You will have to remember to rename it when you upload to the live site though.

random

Posted 2009-10-17T12:30:37.583

Reputation: 13 363

IMHO, this is easily the best answer. Keep in mind that when you upload your site you're going to be on a different server anyway. Meaning that you're probably going to want to use a different configuration there anyway. Most of the time, you just leave these files untouched when you upload and make a separate set for your server. I'd suggest that, if you're developing on Win and uploading to Lin server, you change this setting on the server as well so that those can be edited in Win as well but give the server a different name (eg htaccess.dev.conf and htaccess.prod.conf would be good). – krowe2 – 2016-05-24T14:26:25.660

1One more thing to mention is that most http.conf files include a few lines to prevent downloading of these files... <Files ".ht*"> Require all denied </Files>...change this to <Files "ht*.*.conf"> Require all denied </Files> to keep these files unavailable for download (don't forget to put the missing newlines back in; this is a comment so I removed them). – krowe2 – 2016-05-24T14:31:18.000

One more thing to mention is that, if you're using basic auth, you'll also want to use a similar naming scheme for your .htpasswd files so that they stay hidden as well. – krowe2 – 2016-05-24T14:46:40.303

7Maybe this answer took the "any way to go around it" too literally. – random – 2009-10-17T13:30:35.783

4

Simply name it .htaccess. The ending dot will be automatically removed by Windows, leaving it named .htaccess as it should be.

zeel

Posted 2009-10-17T12:30:37.583

Reputation: 2 766

THis answer should have been the accepted answer most straight forward – Sachin Divakar – 2015-10-29T18:38:52.037

3

This is an exact duplicate of this answer from over a year ago.

– Tim Pietzcker – 2012-01-06T06:38:38.040

2"exact"? No. Anyway, I was lookinfor the answer to this problem and figured it out on my own. But since I had never seen anone say this before, I searched on here for this question, so I could make sure anyone else needing to know got the information. The accepted answer is a lesser answer, so I posted. Didn't notice the othere one. The asker should change the accepted answer to that one though, since it is a far better answer. – zeel – 2012-01-06T16:54:54.917

And you realize it confuses people if an answer is correct, but voted down. Now, while my answer is totally correct, others seeking this information may be mislead by the negative score. – zeel – 2012-07-12T04:29:33.637

3FWIW, I didn't downvote this. But in my opinion, you should remove your answer because the other answer is much better: it doesn't just say "It's magic!" but explains why it works. And you were about a year late with yours. – Tim Pietzcker – 2012-07-12T05:22:01.240

2The previous answer does not mention explicitly: that the trailing dot will disappear - that way this answer still holds its ground. – Ujjwal Singh – 2012-12-06T10:03:51.037

4

I think in the old Windows XP days it was sufficient to just quote the filename? Those quotes would then be removed by Windows. So, rename to save the file as:

".htaccess"

This surely only works when saving from, say, Notepad, and then also keeps the default .txt from being added. I am not 100% sure it also worked in Windows Explorer. In Windows XP, it does not work from Windows Explorer though, as one cannot even type quotes then. And without the quotes it would yield "You must type a file name." because it doesn't like the leading dot. The same errors when using the dialog as shown using right-click » Properties.)

Arjan

Posted 2009-10-17T12:30:37.583

Reputation: 29 084

0

The official (i.e. non-hacky) way to bypass Windows filename limitations is to use the special CMD prefix \\?\ followed by the absolute (i.e. full) path to the file.

This prefix and the related form \\.\ allow you to bypass use of the Windows API directly, and can also be used in the same way to get around other Windows filename limitations such as maximum length (useful for deleting files whose paths are too long to be deleted normally).

To rename a file to .htaccess, simply run the following in a command prompt:

rename "\\?\B:\Users\Me\Desktop\TEST.txt" ".htaccess"

Note that the full path to the file is necessary - because the \\?\ syntax sidesteps the Windows API itself, it loses the ability to resolve relative path names, so an absolute path is needed for it to know where the file is.

Hashim

Posted 2009-10-17T12:30:37.583

Reputation: 6 967