1

I removed Amp Module from our site and I need to remove amp word from center of all of urls.

Using Nginx Web server for example :

mysite.com/shirt/nike?amp=1&product_list_dir=asc&product_list_order=off

should be:

mysite.com/shirt/nike?&product_list_dir=asc&product_list_order=off

or

mysite.com/shoes/nike?amp=1&product_list_dir=asc&product_list_order=off

should be :

mysite.com/shoes/nike?&product_list_dir=asc&product_list_order=off

Please Help Thank You!

1 Answer 1

0

I believe this would work.

    server {
    listen 80;
    server_name mysite.com;

    location / {
        if ($args ~* (.*)(\?|&)amp=1(&.*|$)) {
            set $args $1$2;
        }
        rewrite ^/(.*)$ /$1$is_args$args last;
    }

    # ... other server configuration ...
}

you have to edit your virtual host on your Nginx. It should be in this directory...

/etc/nginx/sites-available/mysite.com

In the configuration above, you should first check if the query string contains the "amp=1" parameter using a regular expression in the if block. If it does, we use the set directive to remove that parameter from the query string. Then, we use the rewrite directive to rewrite the URL without the "amp=1" parameter. This configuration should work for the examples you provided.

Then test your Nginx config that have no confilict

sudo nginx -t

If there was no conflict then just soft reload your Nginx.

sudo nginx -s reload

I hope this works for you.

4
  • Hi thank you for your solution i tried but doesn`t works Oct 12 at 8:52
  • Internal error 500 server Oct 12 at 9:43
  • @peymanpeymani you have to customize the configuration, maybe the root directory in your case is different, you also need to check your nginx log to fine the what is wrong.
    – R1w
    Oct 12 at 13:05
  • @peymanpeymaniyou can provide more detail like logs in case you need more help.
    – R1w
    Oct 12 at 13:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .