The htaccess Rules for all WordPress Permalinks

by Jeff Starr on Wednesday, June 14, 2006 110 Responses

I recently performed a series of tests on a fresh installation of WordPress 2.8.6 to determine the exact htaccess rewrite rules that WordPress writes to its htaccess file for various permalink configurations. Under the WP admin option menu, WordPress lists four choices for permalink structure:

  1. Default: http://perishablepress.com/press/?=123
  2. Date and name based: http://perishablepress.com/press/index.php/2006/06/14/sample-post/
  3. Numeric: http://perishablepress.com/press/index.php/archives/123
  4. Custom: /%year%/%monthnum%/%day%/%postname%/

The "default" option is to not use permalinks. The "date and name based" setting invokes the /index.php/%year%/%monthnum%/%day%/%postname%/ rule pattern. The "numeric" setting invokes the /index.php/archives/%post_id% rule pattern. And the "custom" setting invokes whatever pattern is specifically chosen. For our "custom" option, we chose the /%category%/%author%/%postname%/ pattern.

For the test, we began with the common "date and name based" permalink configuration. Then, after invoking the chosen permalink structure, the htaccess file was downloaded and the new WP rules were recorded. After this, the admin permalink settings were switched back to the "default" configuration. Finally, we deleted the new rules and uploaded the htaccess file. This process was diligently repeated for each different permalink configuration. It should also be noted that blog performance was checked during each round of testing.

The results indicate conclusively that WordPress uses the exact same set of htaccess rules for all permalink configurations. Surely this information is available elsewhere on the internet, however we were experiencing several inconsistencies related to permalink structure that inspired us to determine for ourselves the precise htaccess rules for WordPress permalinks.

Without further ado, the htaccess rules for all WordPress permalinks1 are precisely either #1 or #2:

[ #1 ] If WordPress installed in the root directory »

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

[ #2 ] If WordPress installed in a subdirectory called "foo" »

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

1 Note: 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.

About the author

[ Jeff Starr ]

Jeff Starr is a web developer, graphic designer and content producer with over 10 years of experience and a passion for quality and detail. Jeff is co-author of the book Digging into WordPress and strives to help people be the best they can be on the Web. + Follow Jeff on Twitter and subscribe to Perishable Press for quality web-design content delivered fresh.


110 Responses
[ Gravatar Icon ]

Mac#1

Thank you. You have no idea how helpful this was. A site I recently became responsible for (not my own) was hosed by wp’s htaccess shenanigans. Thanks posting.

[ Gravatar Icon ]

Perishable#2

Happy to help — thanks for the feedback!

[ Gravatar Icon ]

gices#3

Wow, i never knew all permalinks structure had the same htaccess rules. Thx 4 the info!

[ Gravatar Icon ]

Perishable#4

My pleasure!

[ Gravatar Icon ]

Michael Fitzpatrick#5

Yet another thank you for putting this together!!! Chalk me up as another happy user of your knowledge-share.

[ Gravatar Icon ]

Peter#6

Hi,

Thanks for the tutorial. My .htaccess file follows the form of #1 above, but I am unsure how to setup permalinks to pages in wordpress, not posts. Is there a specific way of doing this? Much appreciated.

[ Gravatar Icon ]

Peter Dowse#7

Hi

Thank you so much for publishing this article. This helped me to upload the correct htaccess file to my server and get kick arse SEO friendly permalinks working.

Thank you so much….I have been looking for days on the net and this is the only site that has answered my questions AND shown me how to get the proper code in my htaccess file.

Cheers guys….thanks very much!

[ Gravatar Icon ]

Perishable#8

You are very welcome! Thanks for the feedback!

[ Gravatar Icon ]

Michael#9

I’m not much of a coder and also am relatively new to Wordpress and blogging.

When setting up a custom permalink last night WP wrote to my .htaccess - both in my root AND blog folder - as in example #2 above.

My blog is installed off the html root in a folder called - blog.

The WP entry in the root .htaccess prevented me from publishing my website. The entry in the /blog sub-folder I’m wondering if that should be as in example #1 above or, just leave it as is as in example #2?

When I totally removed the WP permalinks entry from the root .htaccess then I could connect and publish to my website again ok.

If my blog is in a subfolder called blog with its own .htaccess then should the WP entry have the subfolder name /blog in there or not?

Thank you.

[ Gravatar Icon ]

Perishable#10

Michael,

When WordPress is installed in a subdirectory, the root htaccess file does not need any WP-related rewrite rules.

The subdirectory htaccess file does need rewrite rules if permalinks are to be used. In this case, the name of the subdirectory must be included in the rewrite rules.

Thus, adapt the code from case #2 and place it into the htaccess file located in the subdirectory containing your blog. Nothing else should be needed..

Regards,
Jeff

[ Gravatar Icon ]

Michael#11

Thanks a lot for your help and quick response Perishable. I appreciate that. I’m beginning to feel like an htaccess expert now :)
Cheers. and keep up the good info. in the blog. We all appreciate that.

[ Gravatar Icon ]

Perishable#12

My pleasure, Michael — glad to be of assistance ;)
Cheers!

[ Gravatar Icon ]

Soni#13

Wow, thanks for this. I’m setting up a new blog and couldn’t figure out why the permalinks tweak wasn’t working. Turns out, it was the subdirectory path in the htaccess file was missing.

Man, I’ve been pulling my hair out for a couple of hours now trying to figure this out and all it took was one side-by-side glance from my file to your examples to highlight the problem. I just wish I’d tumbled over this site sooner, rather than trying to weed through pages of High Geek on the WP forums. (I speak only Low Geek, I’m afraid) :-D

You rock.

[ Gravatar Icon ]

Perishable#14

Thanks for the feedback, Soni — I am glad that you found the information useful. As a proud member of the “Low Geek” Society, I too found the convoluted maze of High Geek documentation far too tedious for any serious attempt at implementing something as important as WordPress permalinks. May the overlords of Low Geekdom bestow a million visitors upon your site!

[ Gravatar Icon ]

Rickart#15

Fast search, fast answer, fast solution. Thank you so much !

[ Gravatar Icon ]

Perishable#16

You are very welcome, Rickart!

[ Gravatar Icon ]

ion#17

Hi,

I have reached your website looking for a solution with my Permalinks. I have just installed my blog and when I change the setip for a more prettty permalinks, the .htaccess file is created as your example above. The problem is I cannot access my blog anymore I get the 403 Forbidden Access message. If I delete the htacces file, it works again.

Do you have an idea what am I doing wrong.

Thanx in advance

[ Gravatar Icon ]

Perishable#18

ion,

Two questions:

1. Which version of WordPress are you using?

2. Is your blog installed in a subdirectory?

[ Gravatar Icon ]

kym#19

I suspect there is something here which can resolve the problem I have been unable to resolve but I’m not sure how to use the information exactly. Everything on my site works, except for pagenav whether it be at the bottom of the main page, an archives page, etc. When you click on one of the page numbers it fails with a 404 because the url has an extra /blog in it. If that were not there it would work. I have tried varies permalink settings and still no good. I found I did not have an htaccess file so I created on and put the string of commands in it that wordpress gave me and made sure the permissions on the file were ok. I tried it in a few different subdirectors. No good. Have you any recommendations for me based on what you have learned regarding wordpress filestructure rules and the htaccess file or anything else really. I’ve been at this for months and it’s making me crazy.
Thanks in advance for any advice.

[ Gravatar Icon ]

Perishable#20

Hi kym,
I suspect this has something to do with the plugin used to generate the page links. May I ask which plugin you happen to be using?
Regards,
Jeff

[ Gravatar Icon ]

kym#21

Oh I’m sorry - I should have said in my original bit of information that this problem occurs no matter what plugin (because I have tried a few hoping it fixes the problem) I use or if I use none at all. I just deactivated the plugin so you can see what I mean. When the page is assembled that /blog is already in there. I should also have said that the wp install is in a sub directory and not htdocs. I’ve thought that to be the root cause of the issue but assumed there was some way to work around it which is why I thought, when I read this thread, that perhaps something about the htaccess file and wp rules would make a difference.

[ Gravatar Icon ]

Perishable#22

kym,
I would recommend scouring your blog for key instances of the word “blog”. For any WordPress-powered site, there are two fundamental components: the database and the physical files (.php, etc.). Assuming that you have closely inspected your htaccess file for any extra instances of the term “blog”, the next thing to do would be scour the database. Using phpMyAdmin (or whatever), log into your WordPress database and execute a search for “blog” on all tables. Depending on the size of your database, you will get the phone book in return, but with a few logical eliminations, you should be able to narrow the search down to one or two target tables. For example, it probably is not necessary to investigate any occurrences of “blog” that are found in anti-spam plugins, feed-reader plugins, and other peripheral plugins; on the other hand, you will definitely want to examine any hits from your options table and any other core WordPress tables containing the term. Likewise, you should also do a comprehensive search of your site files for the target term, and check out each and every result. The point is, that the extra “blog” that is being inserted into the navigation routine has to be coming from somewhere (duh), and so it is just a matter of tracking it down. It may have been 100 times easier to locate a word that is not nearly as common as “blog”, but we work with what we have been given ;) Anyway, I hope this has helped in some way. I realize I am making all sorts of assumptions here, but I am only trying to help ;) Good luck!

[ Gravatar Icon ]

kym#23

I have scoured the files that are available via the admin, edit themes interface but not gone into the server and looked at everything there. I didn’t think about that. I will try it. I should also note that I didnt have an htaccess file. I created one because I’d hoped creating one with the right stuff would fix my problem. Maybe I’ll look into that a little deeper.

I greatly appreciate your help. Thank you for taking the time! If I sort it out I’ll let you know. Thanks again.

[ Gravatar Icon ]

eddie#24

jeff, i’ve seen a lot of articles but yours is one of the best resources on the topic.

i found it because i am moving from MT to WP. i have mt using this permalink format

/mt/archives/postname.html

using wp-admin, i set the custom permalink in WP to

/mt/archives/%postname%.html

i will use htaccess to convert dashes to underscores that are used in lieu of spaces in the post names.

keeping in mind the fact that i am a WP newb, it seems to be the simplest way to guarantee that my google SERPS won’t get dropped… i don’t even know why i would do it another way.

my question is: do you see a problem with doing it this way?

thanks

[ Gravatar Icon ]

Perishable#25

eddie,
Given your stated objectives, your method seems ideal. Although I have yet to experiment with file extensions in permalinks, WordPress should function perfectly well with your stated format. To my knowledge, I don’t recall encountering anything that would suggest otherwise. I would definitely be interested in hearing about your experience with such an implementation as well.
Regards,
Jeff_

[ Gravatar Icon ]

Terrie#26

Thank you for your insight into word press 404 error pages and the permalink structure! I was lost but now I am back up functioning perfectly.

[ Gravatar Icon ]

Perishable#27

You’re welcome - thanks for the feedback! ;)

[ Gravatar Icon ]

Not Impressed By Much#28

You are the absolute best! This is the fix of all fixes! I owe you a million!

[ Gravatar Icon ]

Perishable#29

I love it! Thank you so much for the generous feedback! ;)

[ Gravatar Icon ]

Marcus Hochstadt#30

Hi James,

Boy am I glad I found your blog. :) James, you are my hope…

I tried it with your great instructions above, to no avail though. I always get the same error message; that is,

“Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.”

This happens whenever I change the permalink settings. Once I click on that “Update Permalink Structure” button the browser displays the above message.

That means, I’m then unable to access anything, the site is unaccessible, until I delete the .htaccess file from the root folder (where the blog is located.)

In other words, I installed WordPress 2.3.1 and it seems I cannot modify the permalink structure.

Do you think it can be a problem with my Web host? Although they clearly state I can use a WordPress blog on my site and even offer a one-click installation. Or perhaps I’ll have to indicate a subdirectory that exists on the server for my specific domain, somehow? (like ‘public_html’, which didn’t work either though)

Any thoughts?

My best,
Marcus

P.S. Marry Christmas! :)

[ Gravatar Icon ]

Perishable#31

Hi Marcus,

Good to hear from you ;)

Assuming you are paying attention and following all the required steps, this sounds like a hosting/server-related issue. I would try contacting them and explaining the situation, just as you have done here. If they are reasonably decent, they should be able to troubleshoot from their end and meet you in the middle with a possible solution.

Otherwise, if the problem lands back in your court, you may want to try setting up a temporary test blog and see if you can get permalinks working there.

Good luck!

[ Gravatar Icon ]

Adrian#32

Thanks so much for this post, it helped me greatly in understanding how wordpress implements permalinks under the hood. I installed wordpress under the root directory of my site and realized with mod_rewrite that any other sub-directories off of root that I previously had used would not work…and instead be routed through wordpress and eventually the error page. Is there any way to add exclusions for subdirectories? Thanks for any help.

[ Gravatar Icon ]

Perishable#33

Hi Adrian,

I am a little confused by your question.. are you saying that you have additional installations of WordPress in subdirectories while also running a root installation of WordPress? Otherwise, what type of subdirectory content is being processed by the root rewrite rules?

Regards,
Jeff

[ Gravatar Icon ]

Adrian#34

No, only one installation of wordpress, I just installed it in the root www folder with my webhost. I had other subfolders outside of wordpress I was using for various things. With the rewrite rules on, I can’t access those subfolders anymore, since wordpress picks it up as an error in what it believes to be a permalink. So I was wondering if there was a way to exclude certian folder names from the rewrite rules. Thanks again, I haven’t found any info on wordpress installations with these requirements so I really appreciate your help.

[ Gravatar Icon ]

Perishable#35

Ah, okay.. Thanks for clearing that up for me. Have you tried disabling the rewrite rules in your non-WordPress subdirectories? Create an htaccess file for each folder and add the following rule:

# disable the rewrite engine
RewriteEngine off

And that should do it. After adding that, WordPress permalink rules should not effect the contents of the non-WP subdirectories.

[ Gravatar Icon ]

Adrian#36

Thank you! That worked! I was concerned doing this would mess up my sub-domain setup because for some reason the sub-domain info looked like it was in the rewrite rules of the subfolder in question. But I removed the rewrite rules from the subfolder, and my sub-domain still worked, this time without getting the wordpress error!

[ Gravatar Icon ]

Perishable#37

Excellent news, Adrian — I am glad to hear that the code worked for you. :)

Happy New Year!

[ Gravatar Icon ]

Kyle#38

Thank you, Thank you! I spent hours last night trying to figure this out and stumbled upon this today!

[ Gravatar Icon ]

Perishable#39

My pleasure, Kyle — happy to help! Excellent looking site you have, btw ;)

[ Gravatar Icon ]

scott#40

Hi Perishable,

I’m having a similar issue with wordpress and .htaccess.

I have multiple subdomains under one server. Within each subdomain is a WordPress blog. To avoid canonicalization, I rewrite domain.com to www.domain.com. Unfortunately, wordpress only works as a folder extension of highlevel domain. (eg. maindomain.com/subdomain/blog/)

I tried a few tricks mentioned here and on WP.org, but to no avail.

I was hoping with your experience you might have a quick solution.

Thanks in advance,
Scott

[ Gravatar Icon ]

Perishable#41

Hi scott,

I want to help, but I am having some difficulty understanding your question.. What exactly are we trying to do here? I see that you are working with WP installs on various subdomains, and that you are redirecting non-www URLs to their www counterparts..
— what am I missing?

[ Gravatar Icon ]

sygyzy#42

my site was hacked last night and as part of my research to restore it, two articles of yours came up. I noticed this because of your theme design. Thanks for posting the information. It’s been very helpful.

[ Gravatar Icon ]

Perishable#43

My pleasure, sygyzy — happy to help! ;)

[ Gravatar Icon ]

Jummy#44

Thank you so much for putting this up. I read it and the comments others left but I think my situation is a bit different and I was hoping you’d be able to help me out.

My blog is located at http://domain.ca/blog. I have a .htaccess file in that folder with chmod 666

I put your code from #2 above into the .htaccess file, changing the two instances of ‘foo’ to ‘blog’ (am I supposed to remove the #?)

I activated date and name-based permalinkss then I went to my site and click on the title of an entry, with the hope that it would show only that entry on the page and the new improved permalink above. Instead, my header image disappeared and all the entries on the page are still visible.

However, when I use the default permalinks and click on the title of the entry, the single entry shows up and I can still see my header image.

I hope this makes sense. Would you have any idea why this is acting this way?

Thank you for your time!

[ Gravatar Icon ]

Perishable#45

Hi Jummy, I am not too sure about what the issue may be with your permalinks, but I can try to address a few concerns in hopes that something might click. First, you should not remove the # (pound signs) from the code. They are used in htaccess to denote a line containing a comment, which is information that should not be processed by the server. Second, keep in mind that the htaccess code provided in this article is the code used for all permalink formats (default, name-only, date-only, etc.), and should be an exact replica of the code that is automatically generated via WordPress. Finally, after you have implemented permalinks on your site, you may want to investigate any plugins, scripts, and/or theme code involved with the display of your header image. Beyond this, it is really difficult to say without a more thorough understanding of your particular WordPress setup and server environment, etc. In any case, I hope that helps provide some clues for you to consider. Good luck!

[ Gravatar Icon ]

Jummy#46

Thank you very much! I think the whole process of submitting my problem to you and thinking on what you said helped me figure out my problem.

My header image wasn’t showing up with individual posts because I had a relative link instead of the absolute link, so it wasn’t related to the above code not working.

I appreciate your help. :)

[ Gravatar Icon ]

Perishable#47

That’s great, Jummy! I am glad to hear that everything is working now. Thanks for the follow-up! Cheers :)

[ Gravatar Icon ]

Russell#48

So I’m curious if it is then possible to password-protect just one Wordpress url. (Wordpress has a post-level protection built-in but it stinks.) Would you not write this beneath your rewrite rules?

# password-protect single file
<Files index.php?p=67>
 AuthType Basic
 AuthName "This area is restricted to registered users"
 AuthUserFile /icslte/.htpasswd
 Require valid-user
</Files>

[ Gravatar Icon ]

Perishable#49

Hi Russell,
It has been awhile since I have dealt with this issue, but if I remember correctly, the trick with WordPress URLs involves using permalinks to get around Apache’s miserable support for query strings. Once you have permalinks enabled, the htaccess code given in your comment should work just fine. I think..

[ Gravatar Icon ]

Scott Fasser#50

Thanks for the good info. I have a problem though. I used version #1 above and was able to generate a link to page from a blog post with the right URL structure, but the content is not being pulled. Can you take a look and tell me what I’m doing incorrectly?

[ Gravatar Icon ]

Perishable#51

Hi Scott,
Without proper access, it is difficult to diagnose for certain the cause of the issue. Based on the URLs having been rewritten, it appears that the htaccess code is working correctly. This leads me to question whether the permalink structure has been defined in the WordPress Admin area. Unless you specify the desired format via WordPress, the htaccess rules will direct the links to nowhere. I hope that helps — check it out and let me know how it goes..

[ Gravatar Icon ]

Ben E#52

This info saved me. It is the only page I found that gives the correct .htaccess code AND indicates that the name of the WP subdirectory (if you have one) MUST be in the .htaccess file EVEN if the file in in that subdirectory. Finally I have an rss feed.

However, is is /?feed=atom. How can I change it to feed=rss? (Do I really needto change it?)

[ Gravatar Icon ]

Perishable#53

Thanks for the positive feedback, Ben. It is great to know that this article continues to help people with their WordPress permalink configuration.

As for the location/URL of your WordPress-generated feed(s), perhaps this article will shed some light on the issue :)

[ Gravatar Icon ]

Kirrus#54

I was setting up a word-press comic for a friend and it didn’t set the .htaccess for me, as my host is paranoid about permissions… Thanks for the invaluable gem here :)

The site, if you’re interested, is here:
http://www.blue-world.co.uk/jaydenandcrusader/

[ Gravatar Icon ]

Perishable#55

My pleasure, Kirrus — thanks for the positive feedback! Best of luck to your friend’s site ;)

[ Gravatar Icon ]

Rich#56

So I am trying to setup WP 2.5.1 with Permalinks. I have done this before with 3 different blogs so I figured I know what I am doing. Of course, they are on a different host so…

Anyway, I set AllowOverride All in the httpd.conf file, then setup the .htaccess correctly (checked it 3 times), setup permalinks, and made a new post. Didn’t work.

On the server we use Apache and a *nix OS (not sure which one since I didn’t set it up).
Any insights would be appreciated. And thanks for the wonderful article that made it all clear.

[ Gravatar Icon ]

Rich#57

Never mind, I dug a little deeper and realized that whoever setup the httpd.conf file left the default directory entry in there and did not put the actual one in. Once I did that and restarted Apache it worked. :)

[ Gravatar Icon ]

Perishable#58

Glad to hear you got it working, Rich! :)

[ Gravatar Icon ]

Mike#59

Hi,

All of the above information is great, but I have a slightly different problem:

On of my sites has a Wordpress blog in the root of the domain, and another website/script in a sub-folder that works with an index.php file.

As a result the pages in the sub-folder are displayed as a Wordpress 404 page.

I have tried turning the Rewriteengine off in the sub-folders htaccess, but that doesn’t seem to help as I guess the Wordpress rewrite rule precede and override it in the folder structure.

Is there a way to modify the Wordpress htaccess so that it ignores certain folders?

[ Gravatar Icon ]

Perishable#60

Hi Mike, have you seen this article on allowing hotlinking in specific directories? That article provides some excellent techniques that should apply to the WordPress Rewrite directives. By simply adding this to your subfolder’s HTAccess file:

# disable hotlink protection
RewriteEngine off

..the WordPress permalink rules should be disabled for all content within that subdirectory. Good luck!

[ Gravatar Icon ]

Mike#61

I tried the RewriteEngine off in the sub-folders htaccess, but for some reason that doesn’t seem to help - I still keep getting a 404 error…

[ Gravatar Icon ]

Perishable#62

Sounds like it could be just about anything, Mike. Without being able to investigate the situation myself, it is really difficult to determine the source of the issue. If it were me, I would try removing various bits of HTAccess from either file until something clicks. Additionally, depending on the type of script(s) that you are using for content in the subdirectory, you may want to experiment with static content, script isolation, and even directory relocation. Any of these things may help diagnose the cause of the conflict. I hope that helps!

[ Gravatar Icon ]

Des#63

Perishable, Is it possible to create an .htaccess file that retrieves and inbound URL it is then redirected from the root level (htdocs) to the subdirectory (htdocs/subdir)?

Currently an URL is typed www.someurl.com, and is defaulting to our main site: www.mainsite.com. Is there a way to retrieve the "someurl.com" and redirect it to www.mainsite.com/subdir?

Thanks in advance for any assistance you can provide!

Des

[ Gravatar Icon ]

Des#64

PS. Perishable, regarding post/question #63, the subdirectory is “wordpress” for our wordpress blog site that was built outside of our hosting provider (network solutions). The version of wordpress being used is 2.5.1. All of this is an FYI if you need to know.

[ Gravatar Icon ]

Doug#65

I am hoping you can help me with my (similar) problem; it seems that you have helped many others.

My blog is about 3 weeks old. I had “Day and Name” Permalinks and all was working well. However, all of a sudden, I started getting 404s on every page, including the home page. I tried everything from theme changes to disabling plug-ins to checking htaccess files to checking mod_rewrite privileges, etc. but nothing worked. I was told that if I changed to default permalinks, it would work. I did and my site came back, but, as you can see, none of my permalinks work. Everything that I click on from my home page takes me back to the home page.

I am just about to do a clean install and I really don’t want to go back and put all my posts back in, so you could really save me here if you have an answer!

Thanks,

Doug

[ Gravatar Icon ]

Jeff Starr#66

Hi Des, try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?someurl\.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1

Replace “someurl.com” with the actual URL. Place in root htaccess file. No other editing is required. Make sure test — the logic is sound, but I have not tested it myself..

[ Gravatar Icon ]

Jeff Starr#67

@Doug: it looks like you beat me to it! I checked your site and the permalinks seem to be working fine. Congrats! :)

[ Gravatar Icon ]

Des#68

Jeff,

I’m not sure if I’m doing something wrong, but it’s not working correctly. I’m not sure if it has something to do with my wordpress files, permalinks, or something else. Gosh this is frustrating–thanks for your help, if you have any other thoughts, I’m all ears–thanks again!!! :)

[ Gravatar Icon ]

Doug#69

Jeff,

Yes, I did beat it! Thanks for checking on me, though! I am almost embarrassed to say what I had done, but, if it helps someone else, I will…

I had, for some stupid reason, changed the URL where my blog is located by adding a /wordpress/ to it, so all my permalinks were citing /wordpress/wordpress/2008/ etc… It took me forever to notice it… oh, well!

Thanks again…

[ Gravatar Icon ]

Jeff Starr#70

That will snag the best of ‘em, Doug. Glad to hear you knocked it out. And thanks for sharing the lesson learned — it is sure to help others in the same boat.
Cheers,
Jeff

[ Gravatar Icon ]

Laurent#71

Hi Jeff,

I have the same problem as Mike on comment 61. What I found out is by turning off the rewrite engine off, it works on the folder itself but not the individual files inside the very folder.

Meaning that if i access the directory manually e.g. my_url/abc it will list the files and then when i click on the files e.g. a photo jpg, it will work. But linking directly the jpg file e.g. my_url/abc/photo.jpg doesn’t work, it will still show the 404 page.

Any workaround on this? I been looking around and even wordpress forums doesn’t have a solution on this.

[ Gravatar Icon ]

Jeff Starr#72

Hi Laurent, I will look into this and see if I can come up with something that works. I have an idea of why this might be happening, but need some time to test it and write it up. I will post back here once I determine the issue and (hopefully) a solution.

[ Gravatar Icon ]

Laurent#73

Thanks Jeff! I look forward to the solution. :)

Anyway awesome site you have here, lots of technical info that I wouldn’t find anywhere else. You got one more loyal reader to your site. Thanks.

[ Gravatar Icon ]

Chetz#74

Hi I had an Internal Server Error when I edited or add the .htaccess on my wordpress directory. I found out a solution from the Internet. Add the following on the first line of your .htaccess file..

Options +FollowSymLinks

That works for me.

Chetz Yusof

[ Gravatar Icon ]

Jeff Starr#75

Yes symbolic links must be enabled on your server in order for the rewrite rules to take effect. In my experience, most servers have this option enabled by default, but some do not. Overriding the default setting via htaccess as you have done here is a sound solution. Another good idea is to wrap the WordPress rewrite rules in an IfModule container to check for the presence of the required functionality. In any case, thanks for sharing, Chetz — much appreciated!

[ Gravatar Icon ]

Chetz#76

You’re most welcome Jeff! I know how frustrating it is to figure out something you don’t know anything about. So, I hope by sharing this info. it’ll help someone.

[ Gravatar Icon ]

Silver#77

Thank you so much for the information.

I used your code for WP install in root above verbatim.

i have my permalinks set to: /%postname%/

My question Is, why do links to pages that are not assigned a page parent (main nav items) not work; however, pages that are assigned to that page parent previously listed do display?

In other words:
Not working - ./about/
Working - ./about/test2/

thank you in advance for your response.
Silver

[ Gravatar Icon ]

Jeff Starr#78

Hi Silver, I am not sure what the issue could be, but you may want to try resetting your permalinks and then re-creating them. Reset them back to WordPress defaults and then delete the WordPress htaccess rules from your htaccess file. Then surf around on your site for awhile to ensure that each of the different types of pages are loading correctly (via the default URL structure). If everything looks good, try enabling your desired permalink format and then replacing the htaccess rules provided in this article, which should be the same as the ones generated by the WordPress admin panel, btw. Hopefully, that will do the trick; but if not, there may other issues involved. I hope that helps!

[ Gravatar Icon ]

g1smd#79

Those .htaccess rules do not fix non-www and www duplicate content issues.

That is a vital thing to add to the mix.

[ Gravatar Icon ]

Jeff Starr#80

@g1smd: You are correct! This article focuses on the htaccess rules for all WordPress permalinks (as the title suggests). I deal with WordPress canonicalization issues separately in other articles. Here are two of my finest efforts, but there are certainly others available via the “Related articles” section at the end of each post.

Comprehensive HTAccess Canonicalization for WordPress.

htaccess Combo Pack: WordPress Permalinks and non-www Redirect

I hope that helps! Cheers!

[ Gravatar Icon ]

Paul#81

Holy crap, you just saved my A$$! Thank you!

[ Gravatar Icon ]

Mark#82

I have been trying to figure this pretty permalink thing out with no success. I implemented your #2 solution. The IT guys installed the mod_rewrite.so instead of mod_rewrite.c. Should this make any difference? I’m pretty new to .htaccess thing.

[ Gravatar Icon ]

Jeff Starr#83

Hi Mark, I am not sure what the issue could be, but a search on Google reveals quite a few questions/concerns about mod_rewrite.so-related issues. I would recommend speaking directly with your IT people; there are many things that they could have done to affect Apache’s rewrite functionality.

[ Gravatar Icon ]

Laurent#84

Hi all, regarding my comment #71 I have found the problem. It was a case-sensitive problem. One of my files had an uppercase first letter and once I change it to lowercase through ftp, it worked perfectly. Does htaccess rules look at case sensitivity? A bit confused here…

[ Gravatar Icon ]

Jeff Starr#85

@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!

[ Gravatar Icon ]

jimsa#86

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.

j.

[ Gravatar Icon ]

Laurent#87

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. :)

[ Gravatar Icon ]

Jeff Starr#88

@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!

[ Gravatar Icon ]

heckennedy#89

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

[ Gravatar Icon ]

Anak Balita#90

this very helpful for me a few hour ago I try to move my blog from http://balitabiz.co.cc/ to http://balitabiz.co.cc/blog/ 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

[ Gravatar Icon ]

jorge orejel#91

hola quiero instalar varios subdirectorios con wordpress

ejemplo:
www.payastitlan.com.mx/
www.payastitlan.com.mx/pestanin/
www.payastitlan.com.mx/prueba/

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

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

example:
www.payastitlan.com.mx/
www.payastitlan.com.mx/pestanin/
www.payastitlan.com.mx/prueba/

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

Greetings and thanks.

[ Gravatar Icon ]

Jeff Starr#92

@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..

[ Gravatar Icon ]

Nick#93

Thanks SO much! This has helped me vastly.

[ Gravatar Icon ]

Justin Foerster#94

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!

[ Gravatar Icon ]

Jeff Starr#95

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

Trackbacks / Pingbacks
  1. robinadr › Greedy WordPress Rewrite Rules
  2. AppliedI.net Windows Webhosting » Blog Archive » The better way to do permalinks in Wordpress on Windows
  3. Enabling and setting up permalinks (custom) in Wordpress | Rotheblog
  4. K4mpun6 Curh4t » Blog Archive » The htaccess Rules for all WordPress Permalinks
  5. Team Programming Dragon.編程龍 » Blog Archive » Permanlink 美化
  6. Wordpress CMS Part 1: Settings And Plugins | Custom Wordpress Theme Design
  7. Про перенесення WP-блоґу на інший хостинг, utf-8 та latin1
  8. WPVote Needs To Improve Published News Section | More Than Scratch The Surface
  9. Balita In Biz
  10. deanet docs » Setting Permalinks Wordpress
  11. Wordpress Permalink Problem | mark-lawton.com
  12. All-In-One: WordPress Plugins & Modifications
  13. WordPress Permalinks 404 when Running in OS X « Transmogrify
  14. Misbehaving Wordpress Site - WordPress Tavern Forum
  15. » My Blog Just Crashed. Lessons Learned From A Recent Experience
Comments are closed for this post

If you have or need further information, contact me.



Previous post: Get Back

Next post: Geek Code Nonsense

Attention: Do NOT follow this link!