【问题标题】:Rewrite url in nginx config在 nginx 配置中重写 url
【发布时间】:2018-06-21 15:42:06
【问题描述】:

我要重写网址

https://www.beecow.info/product/whosaler-san-pham-shop-dang-590-34-390-k-p345954

https://www.beecow.info/whosaler-san-pham-shop-dang-590-34-390-k-p345954

我想删除 /product/ 这是我的 nginx 配置

server {
listen      80;
server_name beecow.info;
return 301 https://www.beecow.info$request_uri;
}

server {
listen       80 default_server;
listen       [::]:80 default_server;
server_name  www.beecow.info localhost;
root         /var/www/html/;

# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
if ($http_x_forwarded_proto != "https") {
   rewrite ^(.*)$ https://$server_name$1 permanent;
}

location ~* ^/product/(.*){
        rewrite ^/product/(.*)$ /$1 last;    
}

location / {
        try_files $uri$args $uri$args/ /index.html;
}

但它不能工作。网址不再改变。

【问题讨论】:

  • 请给我一些建议。非常感谢您的帮助

标签: .htaccess nginx url-rewriting nginx-location


【解决方案1】:

你的重写并没有改变它:

location ~* ^/product/(.*){
    rewrite ^/product/(.*)$ /$1 last;    
}

这样的东西可以完成这项工作(未经测试):

location ~ /product/(.*)$ {
     rewrite ^ /$1?$args permanent;
} 

【讨论】:

  • 谢谢@Aykut。我试过喜欢你的评论,但没有任何反应。位置 / { try_files $uri$args $uri$args/ /index.html; } 位置 ~ /product/(.*)$ { 重写 ^ /$1?$args 永久; }
猜你喜欢
  • 2016-07-04
  • 2014-12-06
  • 1970-01-01
  • 2020-05-26
  • 2013-04-23
  • 1970-01-01
  • 2023-03-08
  • 2022-01-25
  • 2013-12-16
相关资源
最近更新 更多