Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 358
hardy Avatar asked Mar 17 '26 01:03

hardy


2 Answers

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.

like image 104
Denis de Bernardy Avatar answered Mar 18 '26 15:03

Denis de Bernardy


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

like image 37
Bass Jobsen Avatar answered Mar 18 '26 16:03

Bass Jobsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!