skip to Main Content

We have several SEO pages like:

http://www.example.com/PageOne.html

Which we redirect in config like:

location = /PageOne.html {
  rewrite ^/(.*) /seo.php?id=1 last;
}

Problem is if a user access this page by typing:

http://www.example.com/pageone.html

“Page Not Found” error is displaying. There are approximate 500+ seo pages. How to write rule for nginx to ignore case sensitivity in url? I want a common solution for all url.

2

Answers


  1. Chosen as BEST ANSWER

    This solved my issue. Sad to say that there is not many articles related to these issues, even nginx doesn't provide user friendly Help/Tutorials.

            location ~* ^/-PageOne.html {
                 rewrite ^ /seo.php?page_id=1 last;
            }
    

    Hope this helps!


  2. Specifically for PageOne.html, you can do the following:

    location ~ /PageOne.html {
        return 301 http://www.example.com/pageone.html$1;
    }
    

    If you have multiple URIs which need to be redirected, it appears the best option is to use Perl:

    location ~ [A-Z] {
      perl 'sub { my $r = shift; $r->internal_redirect(lc($r->uri)); }';
    }
    

    If you have hundreds of unique URIs which would involve many location blocks as above, I’d consider changing your application to handle lowercase URIs rather than expecting the webserver to handle the lowercase conversion.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search