The missing .htaccess file, FileZilla and ‘Pretty Permalinks’

What is The .htaccess File?

The .htaccess file is a set of server commands that instructs your server to behave in certain ways. Any version of the Apache web server running Unix or Linux will support it. You can do all sorts of great things with it like have custom error messages, password protect files and redirect users. Your web host might allow you to use it, or they might not – it’s better to just email them about it. Anyway, you’re probably wondering what it’s got to do with anything.

Pretty Permalinks and .htaccess

Well, I needed to move my blog from a subdirectory to the root of my domain, www.artbyherbie.com. Also, I was coming around to setting my ‘pretty permalinks’ structure and wordpress needs to be able to write to the .htaccess file when settings are saved. So, I learned that wordpress ONLY creates the .htaccess file, when ‘pretty permalinks’ are enabled in Admin> Settings> Permalinks>. Thanks, I spent a day trying to hunt down this elusive .htaccess file. I use FileZilla 3.3.1 as my FTP client, it’s free and I think better than paid-for rivals such as CuteFTP. Anyway, first I checked my wordpress directory, nothing there. Then, within FileZilla, I went to Server> Force show hidden files>, thinking it was a hidden file on my server. Still, nothing. After some reading around I learned I could call a ‘raw directory listing’ of files within FileZilla, ‘if it’s not listed there, it doesn’t exist’, I was advised.

So, again within FileZilla, I went to Edit> Settings> Debug> and checked ‘Raw directory listing’. FZ spat out the files and guess what, no .htaccess file. Hmm, I thought, little bugger. After some further reading in the WordPress Codex, I learned that the .htaccess file is only created by wordpress once ‘pretty permalinks’ are activated. I WAS hoping to tackle permalinks later on in my project, but I went ahead and added a permalink structure.

I chose the month, year and post/page name structure and saved my settings. This action, I thought, would force wordpress to create the file. However, after looking for the file, I was stumped. It was STILL missing. Smoke was beginning to come out of my ears(!)

File Editing

I even tried another hack, to ‘trick’ wordpress into creating the file. I edited my vars.php file in wp-includes by changing:

$is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false |
to:
//$is_apache = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false |

I commented out the command by adding two slashes infront of it. I then added the following line, underneath:

$is_apache = true;

I saved and uploaded vars.php. Still, this didn’t even work. This elusive .htaccess file was proving to be a mystery. A ‘ding dong’ went of in my mind and I had a thought. My blog was functioning fine and the permalinks were pretty, like they should be. Maybe I didn’t really need this file, after all? So, I started questioning the importance of this file. However, in the process, I learned how to create one, anyway.

How To Create A .htaccess File

In wordpress, it’s best to set your permalink settings to default before proceeding. Save a blank .txt document as ’1.htaccess’. Notice the file name is just the extension itself. Save it as a ’1′ for now on your desktop. Open the file and add the following code:

# BEGIN WordPress


ErrorDocument 404 /index.php?error=404
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress


SecFilterEngine Off
SecFilterScanPOST Off

Save and upload via FTP to your wordpress installation’s directory. Once there, rename it to take out the ’1′ so you end up with just ‘.htaccess’. There should only be ONE WordPress rule within the file. Nothing else. Now go to your web host’s control panel and change the file write permissions to make it writable. After uploading and assigning write permission (755), go ahead and set your permalink structures. Once you’ve done this, go back and set the file permissions to make the file non-writable (644).

The ‘Choke Slam’

Well, by this time, I had still not moved my blog and was confused as to the next step. Until I recieved the following kind message from my web host:

I have consulted with our administrators on the matter, and it seems that the recent versions of the WordPress script do not require .htaccess file, and the permalinks are actually working with it and that is why .htaccess files are no longer included in the installation of the script. Of course, if you wish, you can at any time create a .htaccess file and enter additional rules in it, but the default permalinks no longer depend on that file.
If you wish, you can find a .htaccess file from older WordPress versions at their support forum.

You can probably guess my reaction was a mixture of surprise, frustration and relief. I trusted the man’s knowledge and went ahead with the move.

7 Responses to “The missing .htaccess file, FileZilla and ‘Pretty Permalinks’”

  1. Thanks, the portion of the article outlining how to change the permissions was very useful. I hadnt found any other posts on pretty permalinks outlining this process.

  2. Carroll B. Merriman says:

    good quality subject , i found this after i searched for ages in google, good luck to you. just joined the rss feed to my reader, will definately keep coming back!

  3. robes says:

    awesome article.

  4. trickee says:

    How you find ideas for articles, I am always lack of new ideas for articles. Some tips would be great

  5. jinama says:

    Well your article helped me altogether much in my college assignment. Hats afar to you post, will look forward for more cognate articles soon as its one of my pet question to read.

    • Herbie Hysteria says:

      Lol thanks! I am still developing this weblog, as you can see somepages are still missing tidbits of info etc but don’t worry, i’m going to make this site into one of the best! This blog is still growing so please come back for more stuff very soon. :)

Got something to say? Leave a comment!