Welcome! Log In Create A New Profile

Advanced

The best way to rewrite?

Posted by ThatITGuy 
The best way to rewrite?
October 16, 2010 01:45AM
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?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 122
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready