I have a website built on WordPress. I have been thinking for a while how the pages are actually created by the WordPress. The post pages as well as the other single pages that are created from the admin control panel results in a webpage without WordPress actually creating any folder or directory on the server.

For example, the address of the post is www.example.com/test-post/. But there are no separate folders for any pages or post created from the admin panel.

How is this done?


URLs (what you type into the browser's address bar) and file system paths are two different things. Whilst URLs can map to file system paths, this is not always the case. And with WordPress and many popular database driven CMSs these days, this is not the case.

When you make a request for /test-post/ on a WordPress site, WP intercepts the request and internally directs it to /index.php (the physical file on the file system that actually handles the request). This is entirely hidden from the user; the user only sees the URL in the address bar. WP then looks at the URL (ie. /test-post/) and decides what to do with it (ie. route it)... creates a page and sends the response.

Without WordPress intercepting the request, the web server will indeed try and map the URL to a file system path. A request for /test-post/ will instruct the web server to look for a directory called /test-post. If that directory exists, then it will look for a default index document inside that directory (eg. index.html). If nothing has intercepted the request and if the URL does not map to a file system path then the server will return a 404 Not Found (or 403 Forbidden in some cases).

  • But if the WordPress routes the user to the respective webpages that are retrieved from the database that instance, how can the Google bots discover those pages and index it to their directories? The google bots doesn't know about the page or its URL. How does it crawl though that page without any details? Sep 9 '16 at 10:17
  • 1
    Googlebot cannot see the server configuration. All it can do is download pages and follow links. WordPress creates links to all the pages from other pages. If Googlebot downloads the home page, it will eventually be able to find links to every page on a WordPress site. Sep 9 '16 at 10:38

WordPress implements the front controller design pattern. That is, one file handles all the requests for all URLs. Rather than the server figuring out which file to use based on the URL, the server hands all requests to a central handler that then programatically decides what content to use.

This handler is named index.php in WordPress. It uses rewrite rules in .htaccess to send every request to that controller. The rule that WordPress uses has exceptions such that files that exist on the server take precedence. WordPress then handles all the other URLs.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Once index.php is handling the request, it can examine the URL path, do a database query, and see if there is content for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.