I have a virtualhost that I would like to use rewrite with to clean up some of the URLs.
What I basically need is to have example.com/whatever go to example.com/index.php?p=whatever but treat any other request as a webserver normally would. Each "whatever" page is stored in a file name ending in .dat (like whatever.dat).
My current virtualhost conf is:
[code]
server {
listen 80;
server_name example.com *.example.com;
location / {
root /web/example/html;
index index.php index.html index.htm;
if (-f $request_filename.dat){ rewrite ^/(.*)$ /index.php?p=$1 last; }
}
location ~ \.php$ {
root /web/example/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[/code]
I understand using if inside location is bad, but I couldn't find much of a more sane way of doing it.
Is there a better way to achieve this rewrite?