L
L
lexstile2017-09-06 12:53:01
PHP
lexstile, 2017-09-06 12:53:01

How to exclude index.php and/or index.html from redirect to nginx?

I'm doing a redirect from without a slash to a slash:
rewrite ^(.*[^/])$ $1/ permanent;
How can I exclude index.php and index.html from this redirect?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Mukovoz, 2017-09-06
@lexstile

Like this

if ($request_uri ~ ^/index.(html|php)) { rewrite ^.*$ / permanent; }

B
Boris Korobkov, 2017-09-06
@BorisKorobkov

It's easier (and better for SEO) to do a separate rewrite from "/index\.php" to "/"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question