Removing any text after .html in url

Question

I have following rewrite rules for nginx.

rewrite ^/(.*)/(.*)/(.*).html$ /index.php?first=$1&second=$2&third=$3 last;
rewrite ^/(.*)/(.*).html$ /index.php?first=$1&second=$2 last;
rewrite ^/(.*).html$ /index.php?first=$1 last;

They work all fine for:

domain.com/one.html
domain.com/one/two.html
domain.com/one/two/three.html

However, if i try to open "domain.com/one.html?some-bad-keyword", it will open the page all fine. This could cause duplicate contents if Google crawl/index this page.

How can I redirect "domain.com/one.html?some-bad-keyword" to "domain.com/one.html" OR force nginx to produce 404 page if someone tries to access "domain.com/one.html?some-bad-keyword"

I am using LEMP stack. I am open to PHP solution as well. What would be good from SEO point of view (nginx rules or php solution)?


Show source
| php   | seo   | mod-rewrite   | url-rewriting   | nginx   2017-11-29 20:11 0 Answers

Answers to Removing any text after .html in url ( 0 )

Leave a reply to - Removing any text after .html in url

◀ Go back