D
D
Denisso Russo2016-02-28 17:31:46
Nginx
Denisso Russo, 2016-02-28 17:31:46

How to make autosubstitution "/" at the end of url and exclude pages without it? .htacess or nginx?

You need to write htaccess or nginx rules. I don't even know which is better.
The task is to have auto-substitution "/" in any url and that:
site.com/dir - give 404
site.com/dir/ - give 200
site.com/dir?params - give 404
site.com/dir/?params - gave 200
site.com/dir/index.php | html - gave 404
Now pages are available both with "/" and without it. These are duplicates for search engines - they say bad for SEO.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2016-02-28
@denisgumerov

So can redirects from non-slash pages to slash pages, and not 404? Too many 404s are bad for SEO. And so all users and robots that go to slashless pages will remember that they need to go to slashed ones.

location / {
    ...
    rewrite ^((\/.*)*\/[^.]+[^\/])$ $1/ permanent;
    ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question