Here Is How You Create & Edit WordPress .htaccess File

The .htaccess file is not exclusive to WordPress. Every other Apache web hosting offers the .htaccess file feature.

Confused?

Let us first understand what a .htaccess file is.

What is WordPress .htaccess file?

In most of the cases, when you install WordPress, the .htaccess file comes by default.

However, it stays in hidden mode at the root of your WordPress installation. Sometimes, the .htaccess file is not present, and you have to create the .htaccess file in WordPress manually.

Now, we can use a normal text editor to update or remove the content of our WordPress blog .htaccess file.

Below is the 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

Let us take, for example, a question asked by one of ShoutMeLoud’s readers Kashish.

Q: Hi, I want to edit my Permalink to /%postname? in WordPress, and it says to add some code in my .htaccess.txt file, but I could not find it anywhere in my dashboard or the root directory. How do I create WordPress .htaccess file and add the code into it?

Now, here is how you can solve the problem:

In most WordPress blogs, the .htaccess file resides by default in the root of WordPress installation. If you

 use the 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 options menu, which has been explained earlier.

In case the .htaccess file does not exist, just create a new notepad file (htaccess.txt) and rename it to .htaccess. Make sure that it is not like .htaccess.txt in any way. If you use Windows, you can uncheck the option which says Hide extension for known file types.

Once 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 have a hard time renaming from htaccess.txt to .htaccess, simply upload the htaccess.txt file and rename it on the server.

Sounds simpler now?

No?

Let us further learn how to can edit .htaccess file.

For a better understanding, I’m sharing a quick tutorial on how to edit your WordPress .htaccess file.

There are many methods which you can follow, three of which are mentioned below:

  1. From the cPanel.
  2. From the WordPress dashboard.
  3. Using a desktop FTP client.

Moreover, when you edit your WordPress permalinks, you need to update your .htaccess file. If you are a self-hosted WordPress user, you MUST know about the .htaccess file and how to edit it.

How to edit WordPress .htaccess file using cPanel:

Most web hosting companies offer cPanel, which makes it easier for non-technical people to play around with and modify their .htaccess file.

The cPanel is especially useful for non-technical people who need to add or edit some codes. They can quickly do it using this online editor.

First, log in to your cPanel. Click on “File Manager” under the “Files” section.

  • Save

Depending on your WordPress installation directory, you will find .htaccess at the root of your WP installation. If you don’t see it, refer to my create WordPress .htaccess notes to add one.

Select the .htaccess file and click on “Edit”. This will open the editor in a new tab, and you can make changes from there.

Edit WordPress .htaccess
  • Save

Make changes and save the file.

Boom!

Next,

Editing .htaccess from the WordPress dashboard:

There are many WordPress plugins which offer the feature to edit your .htaccess file from the WP dashboard. If you use the SEO by Yoast plugin, you can access it from SEO by Yoast > Edit Files.

  • Save

Editing .htaccess file using FTP client:

This is my favorite method as I love to do things on a desktop. To top it up, FTP clients give you more control.

Use any free FTP client like FileZilla and log in to your FTP hosting account. Browse to the root of your installation. You have to enable Show Hidden Items to see the .htaccess file.

Here is how you can enable it:

FileZilla Menu Options > Select Server > Force showing hidden files

Now, navigate to the root folder of your domain. Your .htaccess file will be at the root of the folder.

Download your .htaccess file and start editing.

Make sure you take a backup of your .htaccess file before you start editing it. You can use your OS default text editor to edit the file. Once it’s edited, upload it back again.

  • Make sure that the permission of your .htaccess file is 644 and NOT 777.

In the upcoming posts, I will be sharing a couple of WordPress .htaccess hacks which will make your life easier.

Keep watching this space.

You might also consider reading:

Do let us know if you still have questions regarding the steps to edit your WordPress .htaccess file.

Do subscribe to our email newsletter to receive more WordPress tutorials!

Subscribe on YouTube

  • Save
Authored By
A Blogger, Author and a speaker! Harsh Agrawal is recognized as a leader in digital marketing and FinTech space. Fountainhead of ShoutMeLoud, and a Speaker at ASW, Hero Mindmine, Inorbit, IBM, India blockchain summit. Also, an award-winning blogger.

19 thoughts on “Here Is How You Create & Edit WordPress .htaccess File”

  1. Thanks man it’s great info. I was searching for it but could not found anywhere finally i found it here. 🙂

  2. Hi Harsh,

    I just screwed up with my .htaccess file… 🙁 can you please help me?

    I was using %postname% as the permalink and recently i used one plugin (Page Links To) to change the permalink to redirect one of the pages in my website to a subdomain but it didn’t work due to some domain issue..but thats ok now I don’t want to link to subdomain. I just wanted the earlier permalink (mydomain.com/%postname%) but what happens is get the 404 page not found error when i link to the earlier url. I tried changing the permalink multiple times…

    I think something would have got changed when i used the plugin. I have uninstalled the plugin and tried to access the page still the same error. But I can see the page in my wordpress admin page with the old url and when I click on ‘view page’ it gives 404 error.

    I have checked my .htaccess file and it seems there is a problem. Below is my .htaccess after the plugin was installed.

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    After going through different posts I have changed i to:

    # BEGIN WordPress

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

    # END WordPress (Basically I removed the- — ‘RewriteRule ^index.php$ – [L]’)

    But as per your post below is the .htaccess

    # BEGIN WordPress

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

    (I hope its for %postname% and not the default one) But its missing the
    (RewriteEngine On
    RewriteBase / ) and Includes
    ( RewriteRule ^index.php$ – [L]) when compared to both the .htaccess what I have tried.

    I’m confused which one should I use out of all these three. I don’t remember what was my original .htaccess.. 🙁 before all these goofups happen. But I was using %postname% permalink.

    I think you will be able to help out with this…I had gone through some of your posts and I feel you are expert in wordpress.
    I would really appreciate your help . I just want to my missing page should be appeared on the website as it was before with the old url (ie. Mydomain.com/%postname%)
    Is this possible or do I need to republish the page with a different url as a new page and use 301 redirect? (But I don’t prefer 301 redirect..)
    Sorry that I have written too much but I hope you understand my issue. Looking forward to your reply. Thanks a lot

  3. I have tried your editing tips using your suggested code as written and it has shut my site down every time! What am I doing wrong?

    1. @Steve
      Are you using FTP method? Can you share the code which you are adding, usually it happens when code is wrong in .htaccess file.

  4. respected all i ask a question on my site up-to 500 pages i read on google …..
    the google xml sitemap submit work only 500 pages but my website pages is over up to 500 what can i do kindly please giv me sudgession

  5. Installed Robot Meta Plugin and successfully edited my .htaccess file for my blog … Learned the other ways to update htaccess file on my blog … Thank you harsh for writing such a informative post

  6. Hello Sir,
    I am Sunil Prajapati. As you wrote above, i did as well but my permalink yet not changed. It is now 404 error showing. Please tell me now what can i do…..

  7. I want to change my permalink structure. Now I need to play with my .htaccess file. I never realized it was right there in my Yoast SEO plugin! Thanks so much for sharing this information. Critical stuff to know in the rare instances you need to modify the .htaccess file. Thanks for sharing!!!

  8. Hi, I think my .htaccess file is hacked. I have All in One SEO pack and it shows .htaccess file but it looks right. Can you please tell me if there are hidden files in .htaccess file then where can I find them?

  9. Hi Harsh,

    Something is changing my htaccess and make my site unavailable.

    In this example see how “RewriteRule ^index\.php$ – [L]RewriteCond %{REQUEST_FILENAME} !-f ” is on one line when is suppose to divide in two:

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    This is happening like one time a week. I have wordfence, stop spammers, bruteprotect and anti-malware. I can’t find anything that could be making does changes.

    Any ideas? Thanks!

  10. it redirects my old links but the links which i have shared on social media are not redirecting and showing 404 error please help

  11. Hi i changed the wordpress permalink structure which is hosted in Ipage. Actually it is not updating automatically .htaccess file. In order to update the file i need to change the permissions for .htaccess ..how can i do it..?
    Could you please let me know soon

  12. Hi
    I just uploaded Maintain Blogger Permalinks and links are redirected to blogger short links, but now all my new wordpress links (which are longer) turn to 404, I uninstalled Maintain Blogger Permalinks but still have that problem,,

    How to remove it and make as it was please?

  13. Hi…
    I have installed wordpress on my sites. They were working fine. But in last 2 days…my site is not working fine. My domain is opening properly in Desktop but not in mobile devices. In mobile devices my domain is redirected to other random domains. Also, then I noticed the changes htaccess file. I have removed the redirection codex but now my sites are not opening properly in mobile devices. They are still fine with desktop. What should I do…any help will be appreciated.

    Regards,

    1. Harsh Agrawal

      @Jitend
      It’s tough to help you with little information. What I would do in such case is, speak to my hosting tech team.

  14. I’ve read over your suggestions for editing .htaccess. My question is this. My interest in the file is that I have a redirect to send users to my Facebook account will I’m working on the website. When I look in the root directory there is .htaccess, .htaccess1, .htaccess”1, .htaccess_old and .htaccessgg. I assume that .htaccess is the only one being used but it doesn’t contain my redirect but it is redirecting. Any thoughts? When I look at redirects using Bluehost tool it doesn’t show up, not unexpectedly, so where is the redirect coming from?
    The .htaccess”1 file contains the correct redirect command.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
45 Shares
[i]
[i]
[i]
[i]
Share via
Copy link