我有2个网站,
http://localhost/bb – phpbb
http://localhost/dp – Drupal
我希望将$server_name/bb/ucp.php?mode=logout&sid=xxxxxredirect到$server_name/dp/user/logout ,sid应该被忽略。
我试过这个:
location /bb/ { index index.php; if ($query_string ~* "mode=logout$") { rewrite ^/bb/ucp\.php http://$server_name/dp/user/logout redirect; } }
这似乎不工作。 谁能帮忙? 谢谢。
我也试过这个:
location /bb/ { index index.php; if ($arg_mode ~* "logout") ## and = instead of ~* too. { rewrite ^/bb/ucp\.php http://$server_name/dp/user/logout redirect; } }
但它也不起作用。
当前整个configuration:
server { listen 80; server_name localhost; add_header X-Frame-Options "SAMEORIGIN"; client_max_body_size 500M; root /var/www; location / { index index.html index.htm index.php; try_files $uri @rewrite; } location /bb/ { index index.php; if ($arg_mode = "logout") { rewrite ^/bb/ucp\.php http://$server_name/dp/user/logout redirect; } } location @rewrite { # needed by Drupal rewrite ^/([^/]*)/(.*)(/?)$ /$1/index.php?q=$2&$args; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; fastcgi_param PATH_INFO $fastcgi_path_info; } }
(不按预期工作)
你应该直接检查参数值。
if ($arg_mode = "logout") {
您可以使用直接参数检查:
if ($arg_mode = "logout") { rewrite ^/bb/ucp\.php http://$server_name/dp/user/logout redirect; }
但是你的方法似乎是合法的,除了错误的正则expression式。 你有一个$符号在最后意味着一行的结束,而在你的例子中你有$server_name/bb/ucp.php?mode=logout&sid=xxxxx logout绝对不是最后。