Welcome! Log In Create A New Profile

Advanced

Re: return 404 from map module default value

August 05, 2011 09:34AM
On Fri, Aug 05, 2011 at 09:21:11AM -0400, zflairz wrote:
> I'm using map module to redirect URLs which have been removed (but
> indexed by search engine).
> But how can I fall back to http 404 response for urls not present in my
> redirect list?
>
> I've tried following, but I got 200 instead of 404:
>
> location ~* ^/404$ {
> return 404;
> }
>
> error_page 404 = /404.html;
>
> map $uri $redirected_uri {
> default /404; #here?
> include /etc/nginx/redirected_uri.txt;
> }
>
> location ~* ^/.+ {
> if (!-f $request_filename) {
> rewrite ^ $redirected_uri permanent;
> }
> }

First, you do not need regexex here:

- location ~* ^/404$ {
+ location = /404 {

- location ~* ^/.+ {
+ location / {

The configuraiton should look like this:

http {

map $uri $redirected_uri {
default "";
include /etc/nginx/redirected_uri.txt;
}

server {
location / {
try_files $uri @redirect;
}

location @redirect {
if ($redirected_uri) {
return 301 $redirected_uri;
}

return 404;
}
}
}


--
Igor Sysoev

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

return 404 from map module default value

zflairz August 05, 2011 09:21AM

Re: return 404 from map module default value

Maxim Dounin August 05, 2011 09:30AM

Re: return 404 from map module default value

Igor Sysoev August 05, 2011 09:34AM

Re: return 404 from map module default value

zflairz August 05, 2011 10:46AM

Re: return 404 from map module default value

Igor Sysoev August 05, 2011 11:46AM

Re: return 404 from map module default value

zflairz August 05, 2011 09:53PM

Re: return 404 from map module default value

António P. P. Almeida August 05, 2011 10:32PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 66
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready