nginx - how do I get rewrite directives to execute before index directives?
Posted
by Daniel Hai
on Stack Overflow
See other posts from Stack Overflow
or by Daniel Hai
Published on 2010-04-12T17:22:15Z
Indexed on
2010/04/16
21:03 UTC
Read the original article
Hit count: 137
nginx
|url-rewriting
I'm trying a simple internal rewrite with nginx to navigate to a sub-directory depending on the user_agent -- mobile browsers go to /mobile, otherwise they go to /www
however it seems that when I rewrite these urls, the index directive is processed before the rewrites, so I end up getting 403 forbidden.
# TEST FOR INDEX
index index.php
# TEST PHONES
if ($http_user_agent ~* '(iPhone|iPod)') {
rewrite ^(.*)$ /mobile$1 break;
}
# OTHERWISE WE ARE DONE
rewrite ^(.*)$ /www$1 break;
when I turn off the re-writes and hit the hostname (http://www.somehost.com/) the index is displayed correctly. When they are on, I have to explicitly navigate to somehost.com/index.php to get the script to run ...
Do I have to explicity test for directories, and then re-write to an index.php file, or is there a simpler solution?
© Stack Overflow or respective owner