Decypher this .htaccess file please

Posted on 2006-05-04
Last Modified: 2008-02-01
I just installed and configured TextPattern on a site of mine. I like the way that it does the URLs because it's not some stupid index.php?a=146 style link. It does all the stuff as /category/ArticleNumber/PostTitle (ie:

There is, of course, no path like that actually on the server. Everything is pulled from the database and it just looks like a valid path courtesy of a mod-rewrite (I think that's what's doing it)

Here's the .htaccess file's contents:

#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#RewriteBase /relative/web/path/

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^(.+) - [PT,L]
 RewriteRule ^(.*) index.php

#php_value register_globals 0

Can somebody decypher that line-by-line? It utterly confuses me.

Forgive my idiocy, and thank you in advance. -Sootah
Question by:Sootah
    LVL 51

    Accepted Solution

    (empty line)
    conditional directive starts
    enable mod_rewrite functionality
    a condition for mod_rewrite (the request URI must exist as file path) OR
    a condition for mod_rewrite (the request URI must exist as directory path)
    if condition matches use URL as is
    (empty line)
    if condition matche and this one is reached replace URL by index.php
    end of conditonal directive
    (empty line)
    LVL 2

    Author Comment

    Hah, now it makes even less sense to me.

    I don't get at what point it converts the /non/existant/path into an index.php?articlenumber=whatever (or whatever format textpress uses)

    OR, is the .htaccess merely telling the server if the path literally does not exist simply go to index.php with no special extras? In that case, how does TextPattern know what article to go to? You'd think that it'd just show the homepage regardless. Does the requested URL get passed to TP somehow?
    LVL 51

    Expert Comment

    the -f and -d option do not use the query-string, for obvious useless reason

    > how does TextPattern know what article to go to?
    what do you mean by TextPattern?
    if you mean the query-string, then you posted conditions and rules to not talke care about it
    LVL 2

    Author Comment

    TextPattern is a Content Management System, like WordPress (or Blogger)

    When I go to a specific article URL, like /section/category/article-title it takes me to it even though that path does not actually exist. How is the information being passed to TextPattern so that it knows what to load?
    LVL 2

    Author Comment

    Here's the actual URL I'm playing with:

    on the server, /articles does not exist. Subsequently, nothing inside of it exists either. Somehow the URL requested is getting passed to the TextPattern software so it knows what article to load.

    Also, I'm playing with what the permalink structure looks like, so I'm not totally sure that URL will continue to work. (Should give you an idea as to what I'm talking about though.)
    LVL 51

    Expert Comment

    if you mean that   articles/7/test-article  is passed somehow to the new URI (index.php), then the answer is no
    To do that you need to know how these strings should be passed to index.php, and then define the RewriteRule proper.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    How to redirect traffic to my server? 6 36
    MySQL with ISAPI 2 41
    External Wordpress Site loads very slow 1 185
    Use System DSN 6 62
    Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
    When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now