If I use mod_rewrite to control all my 301 redirects, does this happen before my page is served? so if I also have a bunch of redirect rules in a php script that runs on my page, will the .htaccess kick in first?
Yes, the .htaccess file is parsed before your script is served.
When a request is made to the URI affected by the .htaccess file, then Apache will handle any rewrite rules before any of your PHP code executes.
Hi!
htaccess is controlled by the webserver. This file will be taken in account before your PHP file.
For example, you could restrict access to a particular folder with your htaccess file. So, it have to be take in charge before your PHP.
Hope this helps.
The .htaccess is performed by Apache before the php script execution. (imagine if the php script is executed and then the .htaccess make a redirection to another page...).
You always can test this with the following command:
wget -S --spider http://yourdomain.com
With this command you see the who is responding to your request.
As all the others mentioned, .htaccess is first.