How to Create and Edit an .htaccess File4:30 with Zac Gordon
In this QuickTip, we're going to discuss how to create and edit an .htaccess file to use with a WordPress site.
[Treehouse presents] 0:00 [Quick Tips][How to Create and Edit an .htaccess File][with Zac Gordon] 0:02 Welcome! 0:05 In this Quick Tip, we're going to learn how to create and edit an .htaccess file. 0:07 An .htaccess file is a low-level file that gives instructions to the server. 0:11 WordPress uses it to create things like pretty permalinks. 0:16 At some point when working with WordPress, 0:20 you will likely have to create and edit this file. 0:23 The file goes directly in the root directory of the WordPress install and should have the file permissions set to 644. 0:26 Let's take a quick look at how to create an .htaccess file and set its file permissions and then finally edit the file itself. 0:35 One of the areas that you will need an .htaccess for in WordPress is to make custom permalink settings. 0:45 Permalinks determine what the URLs of your site will look like. 0:53 If we move from using the default ID-based permalinks to doing something like a post name-based permalink— 0:58 which is more common—and save those changes, 1:07 we should get a message saying, "You should now update your .htaccess file." 1:10 Down below on the bottom of the page, we can see a message that says, "If your .htaccess file were writable, 1:15 WordPress would update this file for you automatically." 1:23 However, because this file does not yet exist and is writable, 1:27 you'll have to manually update this file. 1:31 What we're going to do is create an .htaccess file, make it writable, come back here, update our settings, 1:34 and let WordPress do the rewriting for us. 1:42 To start off, let's go into our text editor and create a new file. 1:44 We'll leave this file blank for now, 1:50 and we'll just go ahead and save it as ".htaccess." 1:53 Now, any time a file starts with a dot, 2:07 it tells the system that this is not an ordinary file, 2:12 and that it's actually giving instructions to the computer or the server itself. 2:16 When we go to click save, 2:22 it will give us a message about that and want to confirm that we do want to use a dot at the beginning of our file name. 2:25 We'll go ahead and click "Use." 2:33 Now that we have this saved, 2:38 let's jump over to the Finder and go ahead and look for this file that we just saved. 2:39 I know that we saved it into this WordPress folder, 2:45 but we can see that it doesn't show up here. 2:49 The reason it doesn't show up is that files that begin with a dot are usually reserved and hidden from view within Finder. 2:51 However, if we use software like Filezilla or FTP software and we come and look into that same folder, 3:00 we can see that the .htaccess file is there, we're just not able to see it within Finder. 3:11 Let's go ahead and drag this file from our local server up onto our live server with Media Temple. 3:20 Next, we want to make sure that the file has the correct file permissions so that WordPress can write to it. 3:30 To do this, we'll select the file, right click, and check file permissions. 3:36 We can see that it's set to 755, which is actually okay. 3:43 So we'll go ahead and save this, come back into WordPress, refresh our page, and click "Save Changes" again. 3:49 We can see that it says the permalink structure has been updated, 4:00 and WordPress is now taking care of editing our .htaccess file for us. 4:05 You may find that in some situations WordPress will automatically create an .htaccess file for you, 4:11 but you will also often need to create this file on your own. 4:19 You should now know, though, everything you need in order to create and edit an .htaccess file. 4:23
You need to sign up for Treehouse in order to download course files.Sign up