【问题标题】:MODx url rewriting nginxMODx url 重写 nginx
【发布时间】:2015-02-04 12:25:35
【问题描述】:

我们有一个 modx 站点,我们正在尝试重写 URL。但每次失败时,它都有类似

的模式

www.example.com/abc.html?arg1=x123&arg2=555L

我们想像这样重写它 www.example.com/hello/x123-555L 我们如何做到这一点

我们正在使用 nginx 服务器

server {
listen 80;
server_name www.example.com example.com;
root /var/www/test;
index index.php index.html;
location ~* .(jpg|jpeg|png|gif|ico|css|js|ttf)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}

location ~ .(aspx|jsp|cgi)$ {
return 410;
}

# exclude /favicon.ico from logs
location = /favicon.ico {
log_not_found off;
access_log off;
}

if ($host = "example.com") {
rewrite ^ $scheme://www.example.com$uri permanent;
}

location / {
root /var/www/test;
try_files $uri $uri/ @rewrite;
}

location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}

#www.example.com/abc.html?arg1=x123&arg2=555L =>  www.example.com/hello/x123-555L
location = /abc-xyz.html {
rewrite ^ /hello/$arg_arg1-$arg_arg2 last;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass  127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_ignore_client_abort on;
fastcgi_param  SERVER_NAME $http_host;
}

location ~ /\.ht {
deny  all;
}
}

【问题讨论】:

  • 没看清楚,这两个链接你想在浏览器中看到哪个,哪个你想实际传到后端
  • 第二个网址是预期的网址

标签: nginx url-rewriting modx-revolution


【解决方案1】:

抱歉还是不明白你要重写哪两个,所以这里有两种情况的解决方案

第一

  location = /abc.html {
            rewrite ^ /hello/$arg_arg1-$arg_arg2 last;
    }

秒

location ~ ^/hello/(\w+)-(\w+) {
    rewrite ^ /abc.html?arg1=$1&$arg2=$2 last;
}

【讨论】:

  • 预期的网址是 www.example.com/hello/x123-555L
  • 还是不行我已经添加了我的conf文件有什么问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-07
  • 2014-05-18
  • 2011-12-10
相关资源
最近更新 更多