I have a Wordpress site that is currently serving AMP pages to mobile visitors.
I’d like to redirect all AMP pages (i.e. https://mysite.com/page/amp/ ) to no AMP pages (i.e. https://mysite.com/page/ ) in order to be able to remove the AMP pluing without loosing traffic.
For some reason whatever I try to modify my config file nothing changes.
My curreny configuration is as follow:
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; location / { rewrite ^(.)$ /$1$2 redirect; rewrite ^(./)amp/$ $1 permanent; try_files $uri $uri/ =404; }
What i’m doing wrong? Thank you
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thanks for the clarification. I have tried also this rewrite option, but it’s still not working: amp pages keep showing up as before I have refreshed caches, of course.
For WordPress, instead of:
try_files $uri $uri/ =404;
… you’d generally want to use:
try_files $uri $uri/ /index.php?$args;
When you have the =404 at the end, you’re essentially telling NGINX that if a directory or file does not exist, throw a 404 error. Since WordPress uses permalinks, the vast majority of the URL’s are not going to exist as files or directories, so the end result is a 404.
For example:
domain.com/category/this-really-cool-post/
If /category/ doesn’t exist as a directory or file, it’s a 404. If /category/ does exist as a directory but /this-really-cool-post doesn’t exist as a directory or file, it’s a 404.
…
As for the rewrite, you might be able to try something like:
rewrite ^/amp(.*) http://$server_name/$1 permanent;
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.