WordPress .htaccess rewrite 解說

26 六月
-

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

^index\.php$ – [L] prevents requests for index.php from being rewritten, to avoid infinite loops. If the request is for index.php the 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.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

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.

這篇文章的迴響已關閉