I have this directive in my nginx virtual host file:
try_files $uri $uri/ /profile.php?nickname=$uri&$args;
It works ok, but I want to rewrite only 0-9a-z- characters so that users have nice profile addresses, for example:
http://www/mydomain.com/john
But nginx rewrites everything. For example, if I enter address:
http://www.mydomain.com/non-existing-holder/nonexisting-filename.html
instead of returning 404 error it rewrites everything.
Is there any way how to rewrite only 0-9-a-z- characters?
server {
listen 80;
server_name www.mydomain.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /var/www/mydomain;
error_page 404 /4044.html;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /profile.php?nickname=$uri&$args;
rewrite ^/forum/([0-9-]+)/([0-9a-z-]+).html$ /forum.php?tid=$1&title=$2 last;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
You can try the following configuration.
.