2

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

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 build a simple version of that?
asked May 23, 2009 at 9:09

3 Answers 3

6

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.

answered May 23, 2009 at 9:35
Sign up to request clarification or add additional context in comments.

2 Comments

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

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"

answered May 23, 2009 at 9:30

1 Comment

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

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.

answered May 23, 2009 at 22:53

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.