Skip navigation

Getting Under the Skin of the .htaccess File

I have a confession to make. Personally, when I think about touching my .htaccess file, I break out in a sweat and start shaking. It’s not that the .htaccess file is so scary. It’s not. But it can be. I know that if I flub it up, even a little, my site is toasted.

WordPress and its famous pretty permalinks makes exploring the .htaccess file even more frightening with its sophisticated coding that controls how your web page address (URL) will look when displayed. Reading through the code, I swear it’s a highly encoded secret spy message from an alien race. You think I jest? Here, look. This is an excerpt from one of their secret encrypted messages:

RewriteRule ^author/([^/]+)/?$ /index.php?author_name=$1 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1
   &monthnum=$2&day=$3 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ 
   /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /index.php?
   year=$1&monthnum=$2&feed=$3 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?
   year=$1&monthnum=$2&paged=$3 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&
   monthnum=$2 [QSA,L]
RewriteRule ^([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?
   year=$1&feed=$2 [QSA,L]
RewriteRule ^([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ /index.php?
   year=$1&feed=$2 [QSA,L]
RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /index.php?year=
   $1&paged=$2 [QSA,L]
RewriteRule ^([0-9]{4})/?$ /index.php?year=$1 [QSA,L]
RewriteRule ^([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?
   author_name=$1&feed=$2 [QSA,L]

See? It’s really a message from aliens.

Whether or not you can read the above .htaccess snippet, there is still a lot of mystery behind what the .htaccess file is and how it works, as well as how to break the secret code and make it work for you.

Brainstorms and Raves’ article, “Behind the Scenes with Apache’s .htaccess” is a wonderfully simple step-by-step look at what the .htaccess file is and how it makes your website or blog work.

I prefer to think of .htaccess as just one of a variety of approaches and tools for managing URLs (especially URL redirecting), managing custom error pages, and combating bad bots and spammers. It’s a fantastic tool that I’m thrilled to be able to use for my own websites finally, including this one.

Regarding combating bad bots and spammers, .htaccess is one of several tools and approaches that I use. My goal is to keep things simple and block the bad guys without blocking everyone else. No one single approach can do it all, though, and bad bots and spammers continually work on ways to get past all the blocking approaches discussed online. So far I’m able to block nearly all of the bad bots and spammers, but new ones always come along, so I watch my logs closely, too.

The .htaccess file is just one of the many tools web page designers and developers have at their fingertips to create their website or blog. It’s important to learn how to use the .htaccess. file as a tool, and to not be afraid of it. I’m still learning, as I shake in my sandals.

Go forth, brave web and blog designers and developers, and conquer the .htaccess file!


Site Search Tags: , , , , , , ,
Copyright Lorelle VanFossen, member of the 9Rules Network Feed on Lorelle on WordPress Subscribe   Email Subscription

Member of the 9Rules Blogging Network

12 Comments

  1. Karen
    Posted May 13, 2006 at 7:06 pm | Permalink

    Thanks for your post on pretty permalinks. I’ve just installed WordPress, created some static pages, like About and Contact, and can’t figure out how to setup pretty permalinks for the pages. Since the pages aren’t categories nor posts, I don’t know what parameter I’m supposed to use for pretty permalinks.

    I’ve visited the WordPress codex several times, but can’t find info on static pages and permalinks. Perhaps I missed it somewhere. Any advice?

  2. Posted May 14, 2006 at 12:46 am | Permalink

    You don’t have to do anything for Pages. Just take the code as created with Permalinks and put it into your .htaccess file. It will automatically take care of Categories, Pages, etc. Don’t worry about it. It’s taken care of.

    Now, if you are writing your permalinks code by hand for Apache, then start digging into the books and manuals. I’ve no clue.

    In general, your “About” page will be example.com/about and everything will take care of itself. You can also set the name of the About, Contact, and other pages “name” by entering it in the post-slug form section on the Write Page panel. I don’t recommend changing the name of your About or Contact Pages because that is what people commonly look for, but if you have a Page called “Page of Events”, you can change the post slug to read “Events” while the title of the Page is still “Page of Events”.

    Good luck but don’t stress. It’s taken care of.

  3. Posted March 28, 2007 at 6:04 pm | Permalink

    Hello Lorelle, I have come upon your site several times in my efforts to solve my problem. Our site was designed by someone using worpress with the mistylook 101 template. She did a great job and handed it over to us in fine working order. I decided I wanted to have a homepage that was not the blog page so added it, made a few changes to the navigation in the header file and the index.php and now the pages aren’t working at all. The postings are not updating and the about and contact pages both point to the main page. I have been unable to contact the developer and am completely frustrated.
    Thank you!
    Susan

  4. Posted March 28, 2007 at 6:28 pm | Permalink

    I bet you are frustrated.

    I cannot personally help you, and you are going to personally need some help. I recommend several things.

    First, hire someone. I recommend WordPress Consultants on Automattic, the parent company of WordPress, and/or the WP-Pro mailing list to find an expert to fix things.

    Second, if you want to do this yourself, it will take some work to undo what you did, all of what you did, and follow the instructions in Creating a Static Front Page, WordPress Secrets: The Real Ultimate Static Front Page, and OnLamp – From Weblog to CMS with WordPress. If you can get it cleaned up as it was, you can also use one of the “front page” Plugins in WordPress Plugins for Blog Layout, Formating, and CSS Designs to control a static front page.

    Good luck with this. Sorry that you didn’t get a follow-through designer. I hope this helps.

  5. Wordpower
    Posted May 24, 2007 at 2:53 pm | Permalink

    I wanted to use WordPress as a CMS like this website. But I have important folders inside. For example, domain.com/gallery I wanted to put WordPress on top, how can I modify htaccess so that domain.com/gallery will work properly?

    Thank you in advance. I hope you must have done the same thing..

  6. Posted May 24, 2007 at 4:35 pm | Permalink

    This site is a blog, not a CMS. I have no access to “folders” on the server. What you see in the URL are virtual folders created with permalinks.

    Blog and CMS and websites today do not use folders in the way your computer uses folders and directories. They are created “virtually”. With permalinks, you can create a “category” which looks and acts like a folder but a folder really doesn’t exist. The URL would read /example.com/gallery/blah-blah but you wouldn’t have one in reality.

    If you physically want to run WordPress in a specific folder, so the URL and the reality matches, like example.com/blog/... then install WordPress to that folder, and set the Options when installing to that folder as part of the domain address.

    I recommend you read Using Permalinks, Moving WordPress, Integrating WordPress with Your Website, and Changing The Site URL to get more help on this issue.

    When I switched from my static HTML site to WordPress, I had eight folders I wanted to keep in my blog’s URL and had to totally change my thinking to make them virtual categories. It’s a new way of thinking.

  7. Wordpower
    Posted May 25, 2007 at 1:41 pm | Permalink

    Hi Lorelle, thanks… sorry I mentioned wrongly about cms. What I wanted to ask is can I have gallery folder inside wordpress installation? Let’s say I install WordPress on top domain, http://www.domain.com and gallery (coppermine gallery) at http://www.domain.com/gallery Since I will use permalink when I click http://www.domain.com/gallery it always goes to page not out. What could be the solution. I do not want to put wordpress at http://www.domain.com/blog but at http://www.domain.com itself. Thanks again.

  8. Posted May 25, 2007 at 2:37 pm | Permalink

    Your coppermine gallery is not integrated with WorPress and you’ll point to it not as WordPress link.
    You can install Coppermine Gallery where ever you want inside your domain.
    Then pointing to that folder will open the gallery.

  9. Posted May 25, 2007 at 4:39 pm | Permalink

    It looks like you have your answer, but also check the documentation that came with the Plugin or contact the Plugin author directly as they should have the explanation on exactly how to do this. Good luck.

  10. Posted September 13, 2007 at 3:07 pm | Permalink

    I just put up a technology blog and I’m working on getting permalinks worked out. WordPress says for pretty permalinks you need to have a .htaccess file. I’m not in the mood to create one as of yet.

  11. Posted September 13, 2007 at 3:36 pm | Permalink

    Mood? A technology blogger has to be in a mood to create a blank text file called .htaccess?

    LOL. Thanks for the funny. I love it. Good luck with your blog.

    If you are serious, then check out the two minute or less task of doing this in Using Permalinks and Changing File Permissons in the WordPress Codex.

  12. Posted December 26, 2007 at 10:44 pm | Permalink

    Like Susan I too have found this blog of yours countless times no while writing my (many) questions into google to try and solve this wordpress “problem”. Well it’s not really a problem as i’m starting to like wordpress a lot and learning more and more. But my goodness it’s frustrating!!

    I got over the “not being in the mood” buzz a while ago and it was well worth. Partly in thanks to you, Lorelle! Cheers.


4 Trackbacks/Pingbacks

  1. […] Getting Under the Skin of the htaccess File […]

  2. […] Getting Under the Skin of the .htaccess File […]

  3. […] Getting Under the Skin of the htaccess File […]

  4. […] Getting Under the Skin of the htaccess File […]

Post a Comment to Susan McLoughlin

Required fields are marked *
*
*