views:

891

answers:

7

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?

+8  A: 

Yes, the .htaccess file is parsed before your script is served.

Adam Bellaire
+4  A: 

.htaccess happens first.

Jim Puls
+16  A: 

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.

Noah Goodrich
+3  A: 

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.

vIceBerg
+3  A: 

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

p4bl0
+40  A: 
bmdhacks
Could you post a link to image?
Noah Goodrich
edited to add the image attribution.
bmdhacks
Interesting, I did not realize logging happened only after the response was delivered. +1 for finding that diagram.
Tim Post
+1  A: 

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.

DrDol