Question

Can anyone help me please with nginx settings

I have a project in folder /home/test/www/project/

This one contains: *.php //scripts

css, images, videos //folders with content

Open browser with subdomain.domain.com/project/main.php (or index.php - redirect to main.php) click on video, something like this subdomain.domain.com/project/main.php?v=555 everything works well

now i need, short links: subdomain.domain.com/project/555 //where 555 -get request v=555 to main.php

i've tried:

location /project/ {
     rewrite ^/project/(.*)$ /project/main.php?i=$1 last;
}

but after page refresh, i have no images or css styles, only text

the second try:

location /project {
                index index.php;
                if (!-e $request_filename) {
                rewrite ^/([^?]*)(?:\?(.*))? /project/main.php?i=$1 last;
                }
                if ($uri ~* "\.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$") {
                        expires max;
                        break;
                }

        }

Without success. Any help is much appreciated

Was it helpful?

Solution

Try this:

location /projects/ {
    index main.php;
    try_files $uri @rewrite;
}
location @rewrite {
    rewrite ^/projects/(.*)$ /projects/main.php?i=$1 last;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
    expires max;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top