This is the .htaccess code for permalinks in WordPress. I don’t understand how this works. Can someone explain?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I googled and found out that -f and -d part means to give real directories and files higher priority.
But then what are ^index\.php$ - [L] and RewriteRule . /index.php [L] ?
How does WordPress process categories, tags, pages, and etc. with just this?
Does it happen internally? If so, I’m interested in learning how to do it in PHP.
Thanks
^index\.php$ - [L]prevents requests forindex.phpfrom being rewritten, to avoid an unnecessary file system check. If the request is forindex.phpthe directive does nothing-and stops processing rules[L].This block is all one rule, and it says that if it is not a real file and not a real directory, reroute the request to
index.php.index.php itself interprets the URL that was requested by the client (PHP can see the requested URL using
$_SERVER['REQUEST_URI']) and it calls the correct code for rendering the page the user requested.