【发布时间】: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