将.htaccess RewriteRule转换为nginx

时间:2019-02-25 03:17:15

标签: nginx

尝试通过vbout向我们的网站添加vbout个性化网址。他们告诉我将其添加到.htaccess文件中:

#VBOUT EMAIL AND SOCIAL MEDIA SHORTURL .HTACCESS REDIRECT CODE
Options +FollowSymlinks
RewriteEngine on

#BEGIN URL REDIRECT CODE

#SOCIAL MEDIA SHORTURL
RewriteRule ^goto/(.*)$ https://www.vbt.io/goto/$1 [R=301,L]

#EMAIL SHORTURL
RewriteRule ^g/(.*)$ https://www.vbt.io/g/$1 [R=301,L]

#SMS SHORTURL
RewriteRule ^s/(.*)$ https://www.vbt.io/s/$1 [R=301,L]
RewriteRule ^t/(.*)$ https://www.vbt.io/t/$1 [R=301,L]

#END URL REDIRECT CODE

我们使用nginx,因此我尝试将其转换为nginx配置文件。 转换为我所知:

#VBOUT EMAIL AND SOCIAL MEDIA SHORTURL REDIRECT CODE
location /goto {
  rewrite ^/goto/(.*)$ https://www.vbt.io/goto/$1 redirect;
}

location /g {
  rewrite ^/g/(.*)$ https://www.vbt.io/g/$1 redirect;
}

location /s {
  rewrite ^/s/(.*)$ https://www.vbt.io/s/$1 redirect;
}

location /t {
  rewrite ^/t/(.*)$ https://www.vbt.io/t/$1 redirect;
}
#END VBOUT REDIRECTS

尽管重定向仍然无效。这对我来说是陌生的。我的域的完整配置已交换到mydomain.com进行发布。我确定我将其放在错误的位置或丢失了某些东西。任何建议将不胜感激!

# Redirect to https
server {
  listen 80;
  listen [::]:80;

  server_name %{domains};

  include /etc/nginx/snippets/letsencrypt.conf;

  location / {
    return 301 https://$host$request_uri;
  }

  #VBOUT EMAIL AND SOCIAL MEDIA SHORTURL REDIRECT CODE
  location /goto {
    rewrite ^/goto/(.*)$ https://www.vbt.io/goto/$1 redirect;
  }

  location /g {
    rewrite ^/g/(.*)$ https://www.vbt.io/g/$1 redirect;
  }

  location /s {
    rewrite ^/s/(.*)$ https://www.vbt.io/s/$1 redirect;
  }

  location /t {
    rewrite ^/t/(.*)$ https://www.vbt.io/t/$1 redirect;
  }
  #END VBOUT REDIRECTS
}

## Optional, redirect non-www domains to www
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  server_name mydomain.com;

  ssl_certificate /etc/letsencrypt/live/www.mydomain.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/www.mydomain.com/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/www.mydomain.com/fullchain.pem;

  include /etc/nginx/snippets/ssl.conf;

  location / {
    return 301 https://www.$host$request_uri;
  }
}

%{upstream}

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  server_name %{domains};
  root         /home/deploy/%{name}/current/public;

  %{server_config}

  ssl_certificate /etc/letsencrypt/live/www.mydomain.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/www.mydomain.com/privkey.pem;
  ssl_trusted_certificate /etc/letsencrypt/live/www.mydomain.com/fullchain.pem;

  include /etc/nginx/snippets/ssl.conf;

  # Allow uploads up to 100MB in size
  client_max_body_size 100m;

  location ~ ^/(assets|packs) {
    expires max;
    gzip_static on;
  }

  # redirect server error pages to the static page /50x.html
  error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
  }
}

0 个答案:

没有答案