WordPress’s htaccess file (generally) looks like this.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
Using this Rewrite rule, Apache redirects not found URLs to index.php
. And then PHP processes the URL and gives us the relevant data. I have read this at many places.
But actually how does PHP redirect? I would like to understand the technique behind this redirect.
I mean is it using PHP header()
function? Or some other technique?
What the rules mean in plain english:
If the url is
/wordpress/index.php
, stop processing rules.If the requested non-empty url is not a file or a directory, hand the request over to
/wordpress/index.php
and stop processing rules.Internally, WP then considers the original url, matches it against known route patterns using regular expression, and sets the request type and parameters accordingly.
wordpress doesn’t redirect the request. index.php serves the content base on the original request_uri.