0

I am having some problems with regular-expression with rewrite in NGiNX.

Here is my config:

location /wiki/ {
            rewrite ^/([^?]*)/([^?]*)(?:\?(.*))? /$1/index.php?title=$2&$3 last;
    }

Here is the URL of the main page: //example.com/wiki/en/Main_Page

I have two problems.

First when I go to this URL: //example.com/wiki/en

It says the page does not exists. Is there a way to force a / to be added a the end of the "en" at the end of the URL? Because if you go to //example.com/wiki/en/ with the / at the end

Second problem:

The images are not loading.

Here is the URL of the position of MediaWiki images: //example.com/wiki/en/skins/common/images/image name

So is there a way for my regular expression to ignore the URL if it is trying to get an image?

1
location /wiki/ {
    rewrite ^/wiki/en$ /wiki/en/;
    rewrite ^/([^?]*)/([^?]*)(?:\?(.*))? /$1/index.php?title=$2&$3 last;
}
location /wiki/en/skins/common/images/ {
}
3
  • en is the language used. How do you make it so that I can have multiple languages? Thanks.
    – jnbdz
    Nov 24 '13 at 20:24
  • By the way your config works. I just forgot to specify that "en" could be another value. Not more than two.
    – jnbdz
    Nov 24 '13 at 20:26
  • 1
    If in place of "en" there could be any two lower case letters, then use the following instead: rewrite ^/wiki/[a-z][a-z]$ $uri/;.
    – cnst
    Nov 24 '13 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.