Welcome! Log In Create A New Profile

Advanced

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

September 13, 2010 02:52PM
On Mon, Sep 13, 2010 at 01:39:05PM -0400, ez77 wrote:

> > In this configuration:
> >
> > rewrite ^(.*/)index.html http://$host$1 permanent;
> >
> > location / {
> > index index.html;
> > }
> >
> > nginx will not run the server level rewrite, after the internal
> redrect,
> > so there will not be the loop.In this configuration:
> >
> > rewrite ^(.*/)index.html http://$host$1 permanent;>
> >
> > location / {
> > index index.html;
> > }
> >
> > nginx will not run the server level rewrite, after the internal
> redrect,
> > so there will not be the loop.
>
> I still get a redirect this way. Let me point out the "mysite"
> configuration file under /etc/nginx/sites-available/ (too embarrassed to
> give the actual highly-in-construction site):
>
> server {
> listen mysite:80;
> server_name .mysite;
> if ($host ~* .\.(mysite.*)) {
> set $host_without_www $1;
> rewrite ^(.*)$ http://$host_without_www$1 permanent;
> }
>
> access_log /var/log/nginx/mysite.access.log;
>
> rewrite ^(.*/)index.html http://$host$1 permanent;
>
> location / {
> root /var/www/mysite;
> index index.html index.htm;
> }
> error_page 500 502 503 504 /50x.html;
> location = /50x.html {
> root /var/www/mysite;
> }
> }

Sorry, I was wrong: after an internal redirect nginx runs server level
rewrite's. It does not run them if it looks for a new location after location
level rewrite's. So here is working configuration for 0.8.50:

server {
root /var/www/mysite;

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

location ~ ^(?<DIR>.*/)index.html$ {
return 301 http://$host$DIR;
}
}

or you may use

location ~ ^(?<DIR>.*/)index.html$ {
rewrite ^ http://$host$DIR permanent;
}


for 0.7.x and earlier:

location ~ ^.*/index.html$ {
rewrite ^(.*/)index.html http://$host$1 permanent;
}

As to

if ($host ~* .\.(mysite.*)) {
set $host_without_www $1;
rewrite ^(.*)$ http://$host_without_www$1 permanent;
}

please look this:
http://nginx.org/en/docs/http/converting_rewrite_rules.html


--
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: 289
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