Plugin Sale! Save 15% on pro plugins with discount code: FALL2020
Web Dev + WordPress + Security

The htaccess Rules for all WordPress Permalinks

Updated January 24th, 2019: All code current with WordPress 5+. The permalink rules in this article should work with all versions of WordPress.</update>

I recently performed a series of tests on a fresh installation of WordPress to determine the exact .htaccess rewrite rules that WordPress writes to its .htaccess file for various permalink configurations. In the WordPress General > Permalinks settings, WordPress lists six options for permalink structure:

Day and name
Month and name
Post name
Custom Structure

These default permalink options employ the following Structure Tags:

Plain              (permalinks disabled)
Day and name       /%year%/%monthnum%/%day%/%postname%/
Month and name     /%monthnum%/%postname%/
Numeric            /archives/%post_id%/
Post name          /%postname%/
Custom Structure   (user-defined structure)

You can read more about WordPress permalinks at the WordPress Codex.


For the test, we began by enabling the “Day and name” permalink configuration. After saving our changes, we downloaded the .htaccess file that is located in the root directory of our WordPress installation:


We then copied the rules and recorded them in this post (see next section). To verify that the .htaccess rules are the same for all types of permalinks, we tested each of the different permalink options and compared the results. Further, we tested the site for proper functionality during each round of testing.

Once we had determined the correct permalink rules for WordPress installed in its own directory, we repeated the entire test with WordPress installed in the site’s root directory. This test revealed that the permalink rules are different depending on the location of the WordPress installation. Otherwise, the rules are identical, as explained below.


So after much testing, we conclude the following results:

  • Given any WordPress installation, the .htaccess rules are identical for all permalink options.
  • The .htaccess rules only differ when WordPress is installed in its own directory vs. WordPress installed in the site’s root directory.

Surely this information is available elsewhere online, however we were experiencing several inconsistencies related to permalink structure that inspired us to determine for ourselves the precise .htaccess rules for all WordPress permalinks.

The htaccess Rules for all WordPress Permalinks

Without further ado, the .htaccess rules for all WordPress permalinks1 are either of the following, depending on where WordPress is installed.

1) If WordPress is installed in the site’s root directory:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

2) If WordPress is installed in its own directory, /wordpress/:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
# END WordPress

Notice the only two differences between these two sets of rules: the value of the RewriteBase and RewriteRule directives. Specifically, when WordPress is installed in the site’s root directory, the value is /. Otherwise, if WordPress is installed in its own directory, the value is the name of the directory, which is /wordpress/ in this example.


1 These results are valid for standard permalink structures invoked via a standard WordPress install and may not operate effectively for non-standard or highly specialized configurations. We assume that if you are hard at work hacking and tweaking, you must know what you are doing.

Jeff Starr
About the Author
Jeff Starr = Fullstack Developer. Book Author. Teacher. Human Being.
.htaccess made easy: Improve site performance and security.

96 responses to “The htaccess Rules for all WordPress Permalinks”

  1. Hi Jeff

    First off, great site and excellent feedback to various comments!

    I am having a weird (possibly stupid) problem… I have an install of WP in /site folder in the root my site.

    I put .htaccess #2 from your example above into /site (changed the two refs to foo) and removed .htaccess file from the root.

    I then selected ‘Month & Name’ from on the Permalinks page. The index shows up fine but links throught to pages and posts aren’t working, I get a 404 instead.

    Weird thing is that I have other installs of WP within other folders behaving perfectly well!

    Any idea what is happening?

    Many thanks in advance.


  2. Jeff Starr
    Jeff Starr 2008/11/10 5:38 am

    @Laurent: case-sensitivity in mod_rewrite is determined by the presence or absence of the NC (No Case) flag for any of the various RewriteCond or RewriteRule directives.

    Check your rewrite rule (the last line in the IfModule container). By default, WordPress rewrite rules are case-sensitive, so there is no NC flag specified for the RewriteRule. To make the default WordPress permalink rewrite rules case-insensitive, you may add the flag like so (again, last line in the IfModule container):

    RewriteRule . /index.php [NC,L]

    Keep in mind that this is a hypothetical modification we are discussing here; I have not tested this method on any live site, but the logic behind it is very straightforward and should work just fine out of the box. I hope this helps!

  3. Thanks Jeff for the info on the case-sensitivity. All these flags and rules are giving me a headache, I’m thinking of asking my programmer friends to create a simple program to auto generate .htaccess files based on the options selected/needed, or is there one already? Studying .htaccess rules is like learning a new language. :)

  4. Jeff Starr
    Jeff Starr 2008/11/16 4:40 pm

    @jimsa: hi, are you still experiencing the issue? If so, would you mind providing a link to the blog/site in question? I wouldn’t mind having a look..

    @Laurent: No problem, I completely understand about htaccess headaches! ;) As for an application to automatically generate htaccess directives, I have encountered several on various sites online.. try a search for something like, “htaccess generator” via Google and you may find something that does the trick!

  5. heckennedy 2008/12/01 4:00 pm

    Woum thanks!, now i can access to my page.

  6. Anak Balita 2008/12/02 6:25 am

    this very helpful for me a few hour ago I try to move my blog from to but after that i can’t access my setting. and then i looking for the default setting htaccess for wp, after looking for this tutorial for hour a find this…

    THANKS A LOT i know this wp default htaccess not the greatest htaccess but for newbie like me this enough for this time.

    ones again thank’s

  7. jorge orejel 2008/12/03 4:24 pm

    hola quiero instalar varios subdirectorios con wordpress


    y utilizar en todos los Permalinks.
    ¿como configuro el htaccess?

    Saludos y gracias.
    hey I want to install several subdirectories with wordpress


    and use in all Permalinks.
    How do I set htaccess?

    Greetings and thanks.

  8. Jeff Starr

    @jorge orejel: what permalink structure were you hoping to achieve for those subdirectories? Their URLs seem pretty solid simply “as-is”, with no extra modifications necessary. They should work fine by simply linking to them, I would think..

  9. Thanks SO much! This has helped me vastly.

  10. Justin Foerster 2008/12/22 2:47 pm

    Holy moly, I was tearing my hair out yesterday trying to solve this. Funny, I found this page yesterday and tried to do your instructions and it didn’t work.

    Slept on it, and just tried it and … Eureka. Beautiful permalinks without 404 errors.

    Thank you so much!

  11. Jeff Starr

    @Nick, @Justin Foerster: Thanks for the positive feedback! Happy New Year! :)

  12. Janay Green 2011/03/07 12:11 am

    I have a Zen Cart and I just added WordPress. I wanted to say that if you have a Zen Cart and you currently have rewrite rules for one of your mods, then you will need to put the rewrite rules for WordPress in your WordPress directory (mine is called /blog/) That way, your domain will point to your online shop and not your blog.

Comments are closed for this post. Something to add? Let me know.
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
WP Themes In Depth: Build and sell awesome WordPress themes.
Happy Birthday to Perishable Press, celebrating 15 years online! :)
Hide in the basement and hope for the best.
Part of my success is from being able to look ahead down the road and see things coming before they actually get here.
Spent some time refreshing my business portfolio at :)
Tried lots of apps for making animated GIFs from screen captures, so far Kap is my favorite. For example the GIF on this post.
Autumn is my favorite time of year.
Stoked! Had a great interview with Eric over at :)
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.