Hi I want to make a nginx rewrite as fllowing
to
http://my-domain/rates/callrates.php?c=Canada
user will see the url as http://my-domain/Canada and the php will execute the page in the following url
http://my-domain/rates/callrates.php?c=Canada
how to enable this in nginx.conf ?
server { listen 80; server_name my-domain.com; access_log /home/www/my-domain/logs/access.log; error_log /home/www/my-domain/logs/error.log; root /home/www/my-domain/public_html; location / { index index.php login.php; try_files $uri $uri/ $uri.php?$query_string @extensionless-php; error_page 404 /404.php; } location ~* ^/(?<country>\\w+)$ { rewrite ^ /testring/callrates.php?c=$country last; } location ~ \\.html$ { if (!-f $request_filename) { rewrite ^(.*)\\.html$ $1.php last; } } location ~ .*\\.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/www/r2wconnect.com/public_html$fastcgi_script_name; } location @extensionless-php { rewrite ^(.*)$ $1.php last; } }
Assuming that you already have a working PHP configuration...
If your domain does nothing else, the default action could be to invoke the script with:
location / {
try_files $uri /rates/callrates.php?c=$uri;
}
The above has the side effect of leaving in the leading /
.
If you want to make the rule more specific, you could protect it with a regular expression (which also extracts the country name correctly):
location ~* ^/(?<country>\w+)$ {
rewrite ^ /rates/callrates.php?q=$country last;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.