我必须为nginx转换一些htaccess规则。对于丢失的图像,商店系统在图像文件夹中查找动态的小图像。但是商店系统只有apache webserver的信息....也许有人可以帮助我吗?
RewriteCond %{REQUEST_URI} (/product_images/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (\.jpe?g|\.gif|\.png)$ pt_getimg.php
有人能帮助我吗?它必须是第一个重写规则。
我的conf文件:
server {
server_tokens off;
listen 80;
server_name XXXXXXX.de;
access_log /var/log/nginx/MUH.XXXXXXX.de.access.log;
error_log /var/log/nginx/MUH.XXXXXXX.de.error.log error;
rewrite ^(.*) http://www.XXXXXXX.de$1 permanent;
}
server {
server_tokens off;
listen 80;
server_name www.XXXXXXX.de;
access_log /var/log/nginx/XXXXXXX.de.access.log;
error_log /var/log/nginx/XXXXXXX.de.error.log error;
root /var/www/XXXXXXX.de;
index index.php index.html index.htm;
autoindex off;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* /XXXXXXX-backup {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd.XXXXXXX;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include /etc/nginx/fastcgi_params;
}
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|ttf)$ {
expires max;
#log_not_found off;
}
if (!-e $request_filename) {
rewrite /(.*/)?Blog/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+).html.* /blog.php?blog_cat=$2&blog_item=$3 last;
rewrite /(.*/)?Blog/([A-Za-z0-9_-]+)/?.* /blog.php?blog_cat=$2 last;
rewrite /(.*/)?Blog/ /blog.php last;
rewrite /(.*/)?info/([A-Za-z0-9_-]+).html.* /shop_content.php?gm_boosted_content=$2&$args last;
rewrite /(.*/)?([A-Za-z0-9_-]+).html /product_info.php?gm_boosted_product=$2&$args last;
rewrite /(.*/)?([A-Za-z0-9_-]+)/?.* /index.php?gm_boosted_category=$2&$args last;
rewrite /(.*/)?Blog/([A-Za-z0-9_-]+)/?.* /blog.php?blog_cat=$2 last;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include /etc/nginx/fastcgi_params;
}
}
抱歉我的英文不好,希望你能阅读并理解它。谢谢。
答案 0 :(得分:0)
在Apache中使用Rewrite经常完成的是使用nginx中的位置匹配:
location /product_images/ {
try_files $uri @get_img;
}
location @get_img {
rewrite ^.*$ /product_images/pt_getimg.php;
}