Welcome! Log In Create A New Profile

Advanced

Re: Beginner's question: redirecting /dir/index.html to /dir/

September 10, 2010 12:02AM
On Thu, Sep 09, 2010 at 06:22:23PM -0400, ez77 wrote:

> Greetings,
>
> I'm trying to send all .../dir/index.html requests to .../dir/ . I
> looked this up in forums but I'm only able to do it for the root
> directory:
>
> [code]
> location / {
> root /var/www/mysite;
> index index.html index.htm;
> if ($request_uri = /index.html) {
> rewrite ^ http://$host? permanent;
> }
> }
> [/code]
>
> Some day I'll try to stop this copy-and-paste madness, but "in the
> meantime"... could someone please give me a hand? I would greatly
> appreciate it.

You may do it using:

- if ($request_uri = /index.html) {
+ if ($request_uri ~ /index.html) {

However, using "if ($request_uri ..." means that you should use "location"
instead of "if". Nevertheless, the right configuration:

location / {
root /var/www/mysite;
index index.html;
}

location ~ /index.html$ {
rewrite ^ http://$host/? permanent;
}

does not work, because "index index.html" redirects internally "/" to
"/index.html" and you will get endless loop with browsers.
However, you may avoid the internal redirect via try_files:

location / {
root /var/www/mysite;
try_files $uri ${uri}index.html =404;
}

location ~ /index.html$ {
rewrite ^ http://$host/? permanent;
}


--
Igor Sysoev
http://sysoev.ru/en/

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

Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 09, 2010 06:22PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

mat h September 09, 2010 09:52PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

Igor Sysoev September 10, 2010 12:02AM

Re: Beginner's question: redirecting /dir/index.html to /dir/

Igor Sysoev September 10, 2010 12:14AM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 10, 2010 12:51PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

Igor Sysoev September 10, 2010 03:58PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 11, 2010 05:25PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 11, 2010 09:39PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

mat h September 11, 2010 09:48PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 12, 2010 12:13PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

Igor Sysoev September 12, 2010 02:14PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

Splitice September 13, 2010 01:52AM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 13, 2010 03:07AM

Re: Beginner's question: redirecting /dir/index.html to /dir/

mat h September 13, 2010 03:26AM

Re: Beginner's question: redirecting /dir/index.html to /dir/

Igor Sysoev September 13, 2010 04:26AM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 13, 2010 01:39PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

Eugaia September 13, 2010 01:44PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

Igor Sysoev September 13, 2010 02:52PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 13, 2010 06:51PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 13, 2010 06:59PM

Re: Beginner's question: redirecting /dir/index.html to /dir/

ez77 September 13, 2010 07:27PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 319
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