How to Create WordPress .Htaccess File

WordPress being a self hosted Blog, you get the flexibility to play with root folder. Today I’m going to talk about WordPress .htaccess file which is an important file for many reasons. You can set many security settings using Wp .htaccess file, add rules for redirection, block bots, secure your blog from spammers and many more.

Create WordPress htaccess File

Though, many Wp users who are hosting their own blog are still not aware of .htaccess file and how to create .htaccess file in WordPress. Today, we will learn many aspect of WordPress .htaccess file and in future tutorials, I will share some useful codes which you can add to keep your blog secure.

What is WordPress .htaccess file:

.Htaccess file is not only associated with WordPress, but any Apache webhosting offers .htaccess file feature. When you install WordPress, in most of the cases it comes by default but stay in hidden mode at the root of your WordPress installation. Some time, .htaccess file is not present, and you have to manually create .htaccess file in WordPress. We can use a normal text editor to update or remove the content of our Wp blog .htaccess file. This is default code for your WordPress htaccess file:

# BEGIN WordPress
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Here is a question asked by one of ShoutMeLoud reader Kashish: Hi, I want to edit my Permalink to /%postname? in WordPress and it’s showing now to add some code in my .htaccess.txt file, but I could not find it anywhere in my dashboard or root directory. How do I create WordPress .htaccessfile and add the code into it?

How to create WordPress Htaccess file?

In most of wordpress blog .htaccess file resides by default in the root of wordpress installation. If you.htaccess are using Filezilla FTP client, you can refer to my post on how to edit your .htaccess file. all you need to do is click on force showing hidden file, from the option menu, which is already explained earlier. In case .htaccess file does not exist, simply create a new notepad file (htaccess.txt) and rename it to .htaccess. Make sure, it should not be like .htaccess.txt in any ways. If you using windows you can uncheck the option which says hide extension of known file type. hide_extensionOnce you have renamed the file to .htaccess, upload it to the root of wordpress installation and edit your file according to your need. In case you having hard time renaming from htaccess.txt to .htaccess, simple upload the htaccess.txt file and rename it on the server. Do read following .htaccess related articles for WordPress  :

Default permission for security of .htaccess file is 644 but at times when you are changing permalink and WP is unable to access your .htaccess file, you can change it’s permission to 777 and update it. Though, make sure to change it’s permission to 644, else it would cause security issues.

Though his question was specifically for changing permalink and for that I will rather suggest Dean permalink migration plugin and if you like to read about it read : How to use Dean permalink migration plugin. Do let us know if you have any queries regarding WordPress htaccess file, and I would love to answer your query. Don’t forget to subscribe to my Email newsletter for more Wp tips.

Subscribe on Youtube

Article By
Harsh Agrawal is a blog scientist and a passionate blogger. He is blogging since 2008 & writes about Blogging, SEO, Make money online & tech. His blog, ShoutMeLoud receives 1 million Pageviews/month and have over 700K subscribers.


COMMENTs ( 13 )

  1. says

    Hi Harsh,

    I have recently installed the Wp Seo plugin by yoast and it has the option to create .htaccess file. Can I create that within this plugin?

  2. Nikhil says

    Hello Harsh,

    I want to add html file in my site like you are adding it with .html file in your site, then should I changes in my .htaccess file? If yes, then how can I do that? Also, do you have any article about how to add .html files in wordpress then can you please give me the link? So I can follow it.



  3. Anuj Sharma says

    Hi Harsh,

    I have Yoast on my site. However, I do not see .htaccess editor in Yoast. Is something missing?

    Also, my techy friend updated NGinx on the server would that be the reason of not having the .htaccess editor in Yoast?

    Thanks, Anuj

  4. Ankur Agrawal says

    Hello Harsh sir, Another useful post. I checked my wordpress root directory for .htaccess file but there wasn’t any so I made one using notepad as described above and renamed it to .htaccess on the server.
    Now my question is there is nothing in my .htaccess file and I have gone through one of your post ” How to edit .htaccess file”. In that it was written ‘ Make sure that permission of your .htaccess file is 644 and not 777’ .
    So what should I do with my .htaccess file because it is blank.
    Please help . Thank you….

  5. Colorjaws says

    Hello, when I put the .htacss file I have an error, I loose all the access to my WordPress. Any idea why? I am using the wp 3.8.1 thank you

  6. says

    Hi Harsh
    Thanks for the useful info!

    My webhosting company has created a database for me and ftp access for our subdomain. After I have installed WP in the root-folder of the subdomain on their server I am getting the 505 internal server error. They said this is usually to do with either the .htaccess file not being in place and using SEO friendly urls. So I have created the .htaccess file using your default code from this blog but I still cant install WP
    Do you know what causing this error?

    My support is very slow, I am hoping earlier answer here.


  7. says

    hii..harsh watz up..I have one wordpress SEO by Yoast, contains htaccess any thing need to edit..?..I never created one myself…is any thing worry about it??

  8. Ajay says

    Wasn’t aware about .htaccess, thanks for explaining Harsh. Only if you could write one more article for explaining what all these permissions are.