Renaming .htaccess in Windows

I’m sure this has been covered a hundred times, but just in case it hasn’t, I have written a really basic batch file for Windows users to aid in renaming .htaccess files where needed.

For those who do not know, Windows Explorer does not let you rename a file to have only an extension, so .htaccess is invalid. However, you can do it from the command line.

Up until now I’ve just been opening a command window, navigating to the directory and typing in a command to rename it. However, I’ve recently started to explore mod_rewrite a lot more and have been switching the .htaccess file on and off. For this reason I wrote a really simple batch file, as you can see below. If this is of use to even one other person then it’ll make it worth my while. I just hope I’m not reposting something that has been posted many times

Anyway, create a blank .bat file (I called mine htaccess.bat) and edit it, with this code:

echo off
echo Antnee's .HTACCESS switch
echo .
IF EXIST disabled.htaccess (
    ren disabled.htaccess .htaccess
    echo .htaccess ENABLED
) ELSE IF EXIST .htaccess (
    ren .htaccess disabled.htaccess
    echo .htaccess DISABLED
) ELSE (
    echo Nothing happened

Drop this in any directory that has a .htaccess file and double click it to disabled or enable it



IMHO, you do not want anything in your files to mess with your valid .htaccess file. Just because Notepad can’t save as .htaccess doesn’t mean that a usable text editor can’t. EditPad (and Dreamweaver) can save as .htaccess so just create and upload!

Don’t forget your <FILES> block to prohibit anyone touching that file via httpd!



I’m talking about using it locally, not on a public server. It has been useful to me, so the chances are that it will be for someone else too. I have been enabling and disabling it, and I don’t want to load up an editor to change the content, and they can’t change filenames either, they’d just save an extra file. I now have an item that I can just double click to get the effect I want. Simples

If it is only about saving it as .htaccess you are referencing, all you need to do in notepad is add quotes when you save, like this “.htaccess” and the file will be saved the way you see it in your host’s root directory, then to open it, use right button of mouse, and choose Open With

No no, it’s for enabling and disabling it, not for saving it

On windows you shouldn’t need the dot on the front of the name since that isn’t the way that Windows defines a file as being hidden.

But it IS the file that Apache looks for :S

Incorrect, notepad in point of fact can easily save a .htaccess file without issue, when the file is open in notepad simply go to file > save as > select “all files” as the save as type (removing the default .txt extension for saving) and then type .htaccess, and bingo, one clean htaccess document with no added extensions.

If you need to create a file/folder with a dot proceeding it, can use the command line to create it.

Antnee, I know someone who might find this useful, thanks.

Thanks CWebguy. I think things may have been blown a little out of proportion here; it’s just something that some people may find useful, while others may not. I for one find it very handy, and I hope your ‘someone’ does too

yes, I sent them the link. Funny cause they were just asking for something like this. I know, you were just trying to help. Thanks.