The htaccess Rules for all WordPress Permalinks

Published Wednesday, June 14, 2006 @ 6:28 pm • 89 Responses

Note: this article specifically applies to WordPress version 2+ running on Apache servers.

We recently performed a series of tests on a fresh installation of WordPress 2.0.2 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.


Dialogue

89 Responses Jump to comment form

1Mac

August 9, 2006 at 9:36 pm

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.

2Perishable

August 15, 2006 at 6:43 am

Happy to help — thanks for the feedback!

3gices

January 16, 2007 at 2:23 am

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

4Perishable

January 16, 2007 at 11:40 am

My pleasure!

5Michael Fitzpatrick

May 17, 2007 at 11:07 am

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

6Peter

June 9, 2007 at 10:15 pm

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.

7Peter Dowse

August 8, 2007 at 8:25 pm

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!

8Perishable

August 13, 2007 at 8:14 am

You are very welcome! Thanks for the feedback!

9Michael

September 4, 2007 at 7:38 pm

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.

10Perishable

September 4, 2007 at 11:00 pm

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

11Michael

September 6, 2007 at 2:13 am

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.

12Perishable

September 8, 2007 at 1:08 pm

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

13Soni

September 17, 2007 at 4:26 pm

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.

14Perishable

September 18, 2007 at 9:49 am

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!

15Rickart

September 20, 2007 at 3:06 am

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

16Perishable

September 22, 2007 at 8:47 pm

You are very welcome, Rickart!

17ion

September 29, 2007 at 10:38 am

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

18Perishable

September 30, 2007 at 8:35 am

ion,

Two questions:

1. Which version of WordPress are you using?

2. Is your blog installed in a subdirectory?

19kym

October 11, 2007 at 10:43 am

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.

20Perishable

October 11, 2007 at 7:37 pm

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

21kym

October 12, 2007 at 6:21 am

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.

22Perishable

October 15, 2007 at 8:16 am

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!

23kym

October 15, 2007 at 7:52 pm

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.

24eddie

October 16, 2007 at 5:55 pm

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

25Perishable

October 17, 2007 at 7:55 am

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_

26Terrie

November 12, 2007 at 10:06 pm

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.

27Perishable

November 13, 2007 at 12:33 am

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

28Not Impressed By Much

November 27, 2007 at 3:22 pm

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

29Perishable

November 28, 2007 at 12:40 am

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

30Marcus Hochstadt

December 23, 2007 at 3:39 pm

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

31Perishable

December 26, 2007 at 10:59 am

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!

32Adrian

January 2, 2008 at 11:01 am

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.

33Perishable

January 2, 2008 at 12:11 pm

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

34Adrian

January 2, 2008 at 2:53 pm

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.

35Perishable

January 2, 2008 at 4:50 pm

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.

36Adrian

January 2, 2008 at 5:40 pm

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!

37Perishable

January 2, 2008 at 5:57 pm

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

Happy New Year!

38Kyle

January 8, 2008 at 6:53 pm

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

39Perishable

January 8, 2008 at 10:25 pm

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

40scott

January 17, 2008 at 11:01 pm

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

41Perishable

January 20, 2008 at 9:48 am

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?

42sygyzy

February 20, 2008 at 5:24 pm

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.

43Perishable

February 26, 2008 at 6:10 pm

My pleasure, sygyzy — happy to help! ;)

44Jummy

March 22, 2008 at 6:24 am

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!

45Perishable

March 25, 2008 at 1:46 pm

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!

46Jummy

March 25, 2008 at 7:48 pm

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

47Perishable

March 25, 2008 at 8:20 pm

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

48Russell

April 7, 2008 at 6:54 pm

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>

49Perishable

April 8, 2008 at 7:32 am

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

50Scott Fasser

May 13, 2008 at 1:45 pm

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?

51Perishable

May 13, 2008 at 4:02 pm

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

52Ben E

May 17, 2008 at 4:05 am

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?)

53Perishable

May 18, 2008 at 7:17 am

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

54Kirrus

June 15, 2008 at 1:31 pm

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/

55Perishable

June 17, 2008 at 9:47 am

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

56Rich

June 19, 2008 at 6:49 am

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.

57Rich

June 19, 2008 at 10:00 am

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

58Perishable

June 22, 2008 at 8:05 am

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

59Mike

June 24, 2008 at 12:56 am

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?

60Perishable

June 24, 2008 at 6:54 am

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!

61Mike

June 25, 2008 at 12:45 am

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…

62Perishable

June 25, 2008 at 9:37 am

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!

63Des

August 14, 2008 at 11:19 am

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

64Des

August 14, 2008 at 11:23 am

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.

65Doug

August 15, 2008 at 11:52 am

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

66Jeff Starr

August 17, 2008 at 7:20 am

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

67Jeff Starr

August 17, 2008 at 7:24 am

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

68Des

August 17, 2008 at 10:50 am

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

69Doug

August 17, 2008 at 5:48 pm

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…

70Jeff Starr

August 18, 2008 at 4:51 pm

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

71Laurent

September 16, 2008 at 11:26 pm

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.

72Jeff Starr

September 17, 2008 at 9:09 am

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.

73Laurent

September 17, 2008 at 8:57 pm

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.

74Chetz

September 22, 2008 at 7:59 pm

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

75Jeff Starr

September 24, 2008 at 11:24 am

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!

76Chetz

September 24, 2008 at 8:00 pm

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.

77Silver

October 2, 2008 at 9:45 am

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

78Jeff Starr

October 5, 2008 at 2:12 pm

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!

79g1smd

October 6, 2008 at 6:51 am

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

That is a vital thing to add to the mix.

80Jeff Starr

October 6, 2008 at 8:23 am

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

81Paul

October 9, 2008 at 8:07 am

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

Subscribe to comments on this post


Share your thoughts..

TopRead official comment policy

← Previous post • Next post →

« Get BackGeek Code Nonsense »

Contact Perishable Press

  • Contact Jeff via form

Search Perishable Press

About Perishable Press

Perishable Press is the virtual playground of Jeff Starr — visionary, founder and lead developer of Monzilla Media, a small web and graphic design company in the lush desert oasis of Moses Lake, Washington. Perishable Press features articles and tutorials on many aspects of digital design..

Read more..

Perishable on Twitter

automation is great: i've got photoshop batch processing 300+ images while FTP is simultaneously uploading them to the server..

Perishable on Tumblr

Tons of Firewalls

Tuesday, 7 October 2008, 1:45 am

Recently overheard on conservative talk radio (instructing listeners how to obtain a free promotional video from their new website):

“This website has tons and tons of firewalls, so you have to use your real email address to download the video..”

The Quiet Search Revolution

Monday, 6 October 2008, 12:15 pm

Just a thought.. As awesome as Google is these days, it would suck if they ended up owning the entire search-engine business. When they get to the point where all competition is impossible (due to their sheer size, financial resources, media influence, etc.), how many alternate search engines will have the resources for continuous improvement and top-quality search results? When this happens, we will have no choice but to do exactly what Google tells us to do.

As deeply ingrained as it is for everyone to instinctively and unthinkingly turn to Google for their search activity, it is time to leave a few alternate search tabs open for as much use as possible. Instead of using Google just because that’s what you always do, try your search on MSN, Yahoo, Ask, or any of the other independent search engines instead. Sharing traffic with other search engines is a nice, quiet way to keep the competitive spirit alive and well in the search-engine business.

Disappearing WordPress Posts

Wednesday, 1 October 2008, 7:50 pm

Today I experienced difficulties while trying to publish or even save new posts in WordPress. I would compose the post as usual, add all of the keywords, tags, meta tags, and so on, but as soon as I clicked the “Publish” or “Save” button, the post would just disappear from existence.

The weird thing is that during the drafting process, WordPress’ default auto-save feature showed that the post had been saved at expected intervals. Unfortunately, after trying to publish several different posts, WordPress showed absolutely no record of the posts ever being created. They simply vanished into thin air.

Fortunately, a little investigation revealed the culprit. If you should find yourself dealing with this same issue, here are some different things that you should try. First, re-upload fresh copies of your entire WordPress installation. I don’t know why exactly, but apparently various files can either go stale or completely disappear from the server. Overwriting or writing fresh files may do the trick.

If that doesn’t work, check your WordPress database for errors. In my case, a little investigation revealed that something had caused a couple of fatal errors in the wp_posts table. Fortunately, checking and repairing the table solved the issue.

Tumblr Battles

Wednesday, 1 October 2008, 5:30 pm

Please excuse the duplicate Tumbr posts.. seems there is no way to ping Tumblr to refresh/rebuild the RSS feed according to changes in post content. So, to resolve the issue I have discussed now like two or three times regarding paragraph elements and proper feed formatting, I have no choice but to repost a majority of my text posts.

This is necessary for the proper import and display of my Tumblr feed into WordPress. Currently, there are five items displayed at once, each styled according to proper inclusion of paragraph tags. Thus, whenever the Tumblr feed “forgets” to enclose single-paragraph posts with the proper tags, the result is an unstyled post entry displayed on my site.

Assuming that makes sense, you will please excuse my dust while I repost a few older entries in an attempt to reconstruct (the hard way) a properly formatted Tumblr feed.

More Optimization Measures

Wednesday, 1 October 2008, 5:27 pm

Another important step in improving the performance of my recent redesign involves the optimization of both CSS and JavaScript content. During development there were around 15 server requests for these two types of files, 10 JavaScript files and 5 CSS files. This was okay for my own use, but would not work for production purposes.

Optimizing these file types involves consolidation, compression, and caching. Consolidation of 10 JavaScript files into three is huge improvement. Now I deliver one JS file for the functionality of the site, one for Mint, and another for Analytics. Likewise for the stylesheets; after consolidation, a single stylesheet is delivered to all modern browsers. There are two additional stylesheets as well, but they are targeted at IE6 and mobile browsers and will not load elsewhere.

Once the files were consolidated as much as possible, it was time to optimize or “crunch” them. Using the sexy Flumpcakes CSS optimizer, I was able to reduce my stylesheets by around 25%. Likewise for JavaScript, I used xtreeme.com’s optimizer to shave an additional 20% off the size of my JS content.

Finally, once I had consolidated and compressed my JS and CSS files as much as possible, I wanted to further my optimization efforts by ensuring that these files were cached by the browser. By setting far-future Expires headers for everything but the statistical files, my site gains an ad