How is WordPress’ .htaccess and SEO built?

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?

Related posts

Leave a Reply

3 comments

  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”

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