Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx case insensitive url redirection [closed]

I want to do case insensitive url redirection in nginx Below is my code.

location ~* WapsiteDataFetch{
      rewrite  WapsiteDataFetch(.*) http://images.xample.com/xyz/images$1 permanent;
    }

In the above case ,

www.example.com/WapsiteDataFetch is redirected properly to http://images.xample.com/xyz/images however, the url "www.example.com/WAPSITEDATAFETCH" is not redirected properly.

Even if I Change a single character it is giving 404 error.

I have tried many blogs and seen many post from stack overflow and many of them have suggested "~*" but in my case it is not helping me.

please help me as I am stuck on this for a couple of days.

like image 534
Sanjay Salunkhe Avatar asked Nov 30 '22 00:11

Sanjay Salunkhe


2 Answers

Use (?i) to match case-insensitively - http://perldoc.perl.org/perlretut.html

Location block is not necessary. Try this.

rewrite (?i)^/WapsiteDataFetch(.*) http://images.xample.com/xyz/images$1 permanent;
like image 151
Tan Hong Tat Avatar answered Dec 12 '22 03:12

Tan Hong Tat


you can avoid using the regex engine twice, by doing the capturing inside the location block

location ~* WapsiteDataFetch(.*) {
  return 301 http://images.xample.com/xyz/images$1;
}
like image 28
Mohammad AbuShady Avatar answered Dec 12 '22 01:12

Mohammad AbuShady