There is site site.ru , and the script index.php?page=videos , but I want it to open on urla site.ru/myvideo/

But in this case, all CSS/JS , specified not in an absolute way, but relative ( script src="scripts/jquery.js" ), will not be displayed when opening the site.ru/myvideo/ folder.

How can I still configure nginx for this situation?

I realized that it is necessary to make a location block, and try_files in it, but what is more accurate?

  • 2
    @ bo0l, And what prevents to specify absolute paths? - dekameron
  • @dekameron, it is forbidden to modify files where these paths are just registered, I have such a task, I need to register it with the help of the nginx configuration. - bo0l
  • I think you need to look at the comment to this answer - Deonis

1 answer 1

You can use, for example, the following structure:

 location ~ ^/videos/?$ { alias /путь/к/корню/сайта; try_files /index.php?page=videos =404; } location ~ ^/videos/(.+)$ { alias /путь/к/корню/сайта; try_files /$1 =404; } 
  • thanks to the alias directive, the path in these locations will be “computed” from the root of the site, and not from the non-existent “directory” of videos .
  • if it is requested /videos or /videos/ , then an attempt will be made to “call” / /путь/к/корню/сайта/index.php /videos/ /путь/к/корню/сайта/index.php with the parameter ?page=videos
  • if, for example, /videos/каталог/файл is requested, /videos/каталог/файл retrieval /путь/к/корню/сайта/каталог/файл will be tried.
  • in both locations , just in case the previous attempt fails, it is indicated to return error 404
  • so when you request any non-existent static file, /index.php?page=videos will twitch, which, in my opinion, is not correct. We need to write two rules: a complete match url - script. The coincidence is just the beginning - alias + try_files - Sergiks
  • @Sergiks, yes, I didn't think about that. Thanks, corrected the answer. // alias, as I understand it, is necessary in both cases. because index.php, as far as I understand the question, should be called from the root of the site. - aleksandr barakin 6:38 pm