Nha Phuong
Nha Phuong

Reputation: 21

Rewrite url in nginx config

I want to rewrite url

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

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

I want to remove apart /product/ And here is my nginx config

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;
}

But It can't work.The url not change anymore.

Upvotes: 1

Views: 104

Answers (1)

Aykut Çevik
Aykut Çevik

Reputation: 2088

Your rewrite doesn't change it:

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

Something like this will do the job (untested):

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

Upvotes: 1

Related Questions