hardy
hardy

Reputation: 79

How does WordPress internal url rewrite work?

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?

Upvotes: 3

Views: 2528

Answers (2)

Denis de Bernardy
Denis de Bernardy

Reputation: 78443

What the rules mean in plain english:

  1. If the url is /wordpress/index.php, stop processing rules.

  2. 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.

Upvotes: 4

Bass Jobsen
Bass Jobsen

Reputation: 49044

wordpress doesn't redirect the request. index.php serves the content base on the original request_uri.

Upvotes: 1

Related Questions