: How does WordPress create pages without actually creating any folders on the server? I have a website built on WordPress. I have been thinking for a while how the pages are actually created
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 example.com/test-post/. But there are no separate folders for any pages or post created from the admin panel.
How is this done?
More posts by @Samaraweera270
2 Comments
Sorted by latest first Latest Oldest Best
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]
</IfModule>
# 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.
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).
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.