[英]How to use rewrite in Nginx?
I use .htaccess in Apache2, it works well. 我在Apache2中使用.htaccess,效果很好。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_]+)$ profile.php?username=$1
and now I use nginx rewrite, in sites-available, i make this config 现在我使用nginx重写,在站点可用,我做这个配置
server {
listen 80;
server_name domain.com;
root /home/domain;
index index.html index.htm index.php;
location / {
rewrite "^([A-Za-z0-9_]+)$" profile.php?username=$1 last;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
but it doesn't work, it shows 404 Not Found, can you help me the error? 但它不起作用,它显示404 Not Found,你能帮我解决这个错误吗? thanks.
谢谢。
There is a issue with the rewrite translation. 重写翻译存在问题。 Check this updated rewrite translation in this code.
在此代码中检查此更新的重写翻译。
server {
listen 80;
server_name domain.com;
root /home/domain;
index index.html index.htm index.php;
location / {
if (!-e $request_filename){
rewrite ^/([A-Za-z0-9_]+)$ /profile.php?username=$1;
}
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.