• Hi,

    I would really like to understand how WordPress works technically, which (in my case) begins with the .htaccess.

    After a regular install, the .htaccess looks like this:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    I understand this as:

    “If the requested URL neither points to a file not to a directory, then do the following RewriteRule.”

    The RewriteRule only has a dot “.” – which I’d normally understand as a regex wildcard for ONE SINGLE CHARACTER. Basically, to me it reads “move every single character URI to /index.php”, which can’t be correct in my opinion – I know I am wrong, but I wonder why it’s not “.*” for more than one character..

    I am really interested in understanding how WP works.

    For example, I have permalinks set to date and name based:
    /%year%/%monthnum%/%day%/%postname%/

    So, e.g. I type in “(mysite)/2007/06/08/example/”

    How does WordPress know what post to show???

    A. It is no file, so the first RewriteCond does not work
    B. It is no directory, so the 2nd RewriteCond does not work, either.
    C. So the RewriteRule is executed, right?

    What happens next?

    I’d appreciate help on this greatly – thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter saphod

    (@saphod)

    Really, no one? :’-(

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    The RewriteRule only has a dot “.” – which I’d normally understand as a regex wildcard for ONE SINGLE CHARACTER. Basically, to me it reads “move every single character URI to /index.php”, which can’t be correct in my opinion – I know I am wrong, but I wonder why it’s not “.*” for more than one character..

    RewriteRule . whatever simply rewrites *everything* to the index.php. It doesn’t replace each character, just says “if you can match any character, then change to index.php”. The .* would have the same effect, but take slightly more time (milliseconds or less).

    What happens next?

    The index.php is the starting point for WordPress, and it runs, and then executes it’s own rewrite functionality. It has access to the original URL too, and parses it itself.

    Thread Starter saphod

    (@saphod)

    @4k:
    Thanks a lot, but I have already looked at those.

    @otto42:
    Oh, OK, thanks… hmm… is the “.” the normal RegEx-Syntax ? The only thing that I could think of is that there is neither a “^” at the beginning nor a “$” at the end, so that it really catches *everything*… makes sense… anyway, I find “.*” is better to understand.

    OK… as can be seen on https://phpxref.com/xref/wordpress/:

    a) index.php simply loads blog-header.php.
    b) blog-header.php loads classes, functions and plugins.
    c) wp-config.php is included.
    c) wp() is executed –> WHAT DOES THIS FUNCTION DO???
    d) template-loader.php is included.

    Where is this going from here?
    I just do not know where the rewrite-functions start working…

    Stupid me :’-(

    ??

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Oh, OK, thanks… hmm… is the “.” the normal RegEx-Syntax ?

    It’s quite common for RewriteRules, yes.

    anyway, I find “.*” is better to understand.

    Yes, but like I said, it’s slower. On these you want to squeeze out every last optimization.

    a) index.php simply loads blog-header.php.
    b) blog-header.php loads classes, functions and plugins.
    c) wp-config.php is included.
    c) wp() is executed –> WHAT DOES THIS FUNCTION DO???
    d) template-loader.php is included.

    wp-config.php loads a whole lot of stuff. Everything, in fact. Mainly it loads the wp-settings file, which loads and initializes everything else.

    Now, the actual query gets parsed by that wp() call. wp() is a function which basically calls the main() function of the instantiated WP object. Among other things, this calls the WP object’s parse_request function, which uses the WP_Rewrite object to convert the URL into the normal query_vars WordPress uses.

    The short of it is that I think you’re going about this the wrong way. You don’t need to know the order of execution of everything to mess with WordPress. You just need to know what each piece does. When it does it is a little irrelevant, especially on the startup phase.

    Thread Starter saphod

    (@saphod)

    Oh, I see, the wp-settings.php is pretty huge…

    The short of it is that I think you’re going about this the wrong way. You don’t need to know the order of execution of everything to mess with WordPress. You just need to know what each piece does. When it does it is a little irrelevant, especially on the startup phase.

    Well, I do not really want to mess with WP [mostly, it messes with me ;-)], but I just want to understand what happens on the WP side from the moment on when you put in a URL to a post and press return.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Understanding How WordPress Works (Technically)’ is closed to new replies.