Welcome! Log In Create A New Profile

Advanced

Re: NGINX redirection issue

Maxim Dounin
August 07, 2014 04:06AM
Hello!

On Wed, Aug 06, 2014 at 11:37:42PM -0400, manish-ezest wrote:

> Hello All,
>
> I am facing some issue regarding nginx redirection. I want to remove .html
> extension from all the html pages and all the index.html pages. For example
>
> 1.
> http://www.aaa.com/bbb/ccc.html should show the content of
> http://www.aaa.com/bbb/ccc.html but the URL should show
> http://www.aaa.com/bbb/ccc
>
> 2. http://www.aaa.com/index.html should show the content of
> http://www.aaa.com/index.html but the URL should show http://www.aaa.com.

This is something as simple as:

location / {
index index.html;
try_files $uri.html $uri/ =404;
}

with "index index.html" being the default - that is, you don't
actually need to configure it explicitly. Or like this, using
only try_files instead of try_files + index:

location / {
try_files $uri.html $uri/index.html =404;
}


The only potential difference from what you describe is that this
won't do a redirect to hide "/index.html" if explicitly requested
by a user, but it's not clear from your description if it's
something really needed. This is not something usually done.

See here for details:

http://nginx.org/r/index
http://nginx.org/r/try_files
http://nginx.org/en/docs/http/request_processing.html

> There are few rewrites already there which are given below
>
> 1. Whenever you try to access the http://www.aaa.com site, it will redirect
> to http://www.aaa.com/aaa/bbb/ccc/ddd/index.html.
> http://www.aaa.com -----> http://www.aaa.com/aaa/bbb/ccc/ddd/index.html.
>
> 2. All directory lookups to 'index.html'
> rewrite ^(.*)/$ $1/index.html permanent;
> 3. All open strings to index.html
> rewrite ^(.*)/([^\.\?/]+)$ $1/$2/index.html permanent;
>
> Now whenever I try to implement the change, the site went into a redirect
> loop and gives following error in the error log.
>
> 2014/08/05 14:48:03 [error] 10392#0: *750 rewrite or internal redirection
> cycle while internally redirecting to "/index.html", client: 1.1.1.1,
> server: www.aaa.com, request: "GET /aaa/ccc HTTP/1.1", host: "www.aaa.com"
>
> Please suggest how to solve the issue

Both rewrites you've provided will return external 301 redirects
without doing internal redirects, so the loop is caused by
something else in your config. You have to show your config for
others to be able to help.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

NGINX redirection issue

manish-ezest August 06, 2014 11:37PM

Re: NGINX redirection issue

Maxim Dounin August 07, 2014 04:06AM

Re: NGINX redirection issue

manish-ezest August 07, 2014 12:02PM

Re: NGINX redirection issue

manish-ezest August 08, 2014 06:01AM

Re: NGINX redirection issue

Maxim Dounin August 08, 2014 10:52AM

Re: NGINX redirection issue

manish-ezest August 08, 2014 10:49PM

Re: NGINX redirection issue

Maxim Dounin August 09, 2014 09:12PM

Re: NGINX redirection issue

manish-ezest August 29, 2014 04:05AM

Re: NGINX redirection issue

Maxim Dounin August 30, 2014 10:48PM

Re: NGINX redirection issue

manish-ezest September 01, 2014 02:05PM

Re: NGINX redirection issue

Maxim Dounin September 02, 2014 10:00AM

Re: NGINX redirection issue

manish-ezest September 03, 2014 03:53AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 302
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready