views:

440

answers:

3

I have thought about using WordPress – or maybe just copy a few functions to a internal site – but before I'd use it I would like to know how it's working.

I'm thinking that WP is a bunch of slamcode so I'm hoping some of you could help me on how it's built.

How is the .htaccess and URL rewrite combined with index.php? - The .htaccess sends everything to index.php and I have tried to follow every file but I can't see how index.php detects the url. How could I built a simple version of that?

Cheers,

+1  A: 

index.php really gets called with parameters:


index.php?page=55

i'm guessing you're looking for a way to have nice links for seo without the ? parameters

the htaccess part could look like this:


RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)/$ index.php?page=$1 [NC,L,QSA]
  1. we havn't redirected already 2.+3. the link doesnt point to a real file or dir
  2. map the stuff after the slash as page parameter

so eg "www.homepage.com/superpage" gets mapped to "www.homepage.com/index.php?page=superpage"

My .htaccess in the wordpress directory looks like this though: "RewriteRule . /wordpress/index.php [L]" So no page is being sent. I'm still not sure of how everything works.
Josso
+5  A: 

There is a very detailed summary in the WordPress Codex on Using Permalinks.

If you are interested in how it was implemented, see the WordPress Rewrite API in file /wordpress/wp-includes/rewrite.php and check the related reference entry in WP Codex.

Török Gábor
The WP-Codex link was helpful. A link from there to a mailinglist explained how it works – though it was a bit too simple to actually use.
Josso
@Josso: what you are exactly looking for then? The good code describes itself, and I'm afraid, you won't find any more detailed references on how they implemented than the WP Codex entry.
Török Gábor
A: 

Correction... according to the .htaccess rules by default in WordPress and the ones listed below, it will first look if there is a file or a directory that exists in the path given in the URL. If there is no file/directory present at that location, index.php is called.

This ensures that the admin section works the way it does. This also ensures that you can dump any file in the WordPress directory and still be able to access them.

Once the redirection reaches index.php, the WordPress Redirection API is called as indicated by this post.

Adhip Gupta