php - How does Wordpress convert directory requests into database generated pages?
Get the solution ↓↓↓This is a curiosity based question, rather than being related to any issue.
I wondered how Wordpress rectifies pseudo URL addresses (e.g. blog.com/posts/2015/05/05/example_blog_post) to php generated pages? What are the mechanics behind this redirection process?
Answer
Solution:
This is actually a rule from the server config, not the CMS specifically. For instance, the common Apache config is:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
The second-to-last line if "if URL does not exist as a directory, also pass this on to WordPress".
The rest is handled by the rewrite engine which is a bunch of compiled regular expressions. If you have the WordPress CLI you can runwp rewrite list
and it will show you the entire list in priority order:
match | query | source |
---|---|---|
(.?.+?)/embed/?$ | index.php?pagename=$matches[1]&embed=true | page |
(.?.+?)/trackback/?$ | index.php?pagename=$matches[1]&tb=1 | page |
(.?.+?)/page/?([0-9]{1,})/?$ | index.php?pagename=$matches[1]&paged=$matches[2] | page |
(.?.+?)/comment-page-([0-9]{1,})/?$ | index.php?pagename=$matches[1]&cpage=$matches[2] | page |
(.?.+?)(?:/([0-9]+))?/?$ | index.php?pagename=$matches[1]&page=$matches[2] | page |
[^/]+/attachment/([^/]+)/?$ | index.php?attachment=$matches[1] | post |
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: invalid argument supplied for foreach() laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
About the technologies asked in this question
PHP
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.