J
J
JunDevTest2018-08-08 10:41:35
Nginx
JunDevTest, 2018-08-08 10:41:35

How to make a virtual redirect to an index file using Nginx?

Welcome all.
There is an index.php file, there is the main page of the site. For some reason, the CMS will not detect the homepage and will display its own 404 error. At the same time, if you explicitly go to the address: https://example.com/index.php everything works and the main page opens. The index file in the Nginx config is set correctly.
index index.html index.php;
Well, actually it works, since the main page of the site opens, the error is most likely somewhere on the application side. But in view of the lack of such experience, I do not know where to look for it. Now I temporarily solved the problem like this:

if ($request_uri = "/") {
    return 301 "/index.php";
}

Of course, it works, but /index.php appears in the URL (it's understandable, 301 redirect is the same). How to make a virtual redirect ( symlink ) to index.php, for example, using location and rewrite without physically going anywhere?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2018-08-08
@freezl

I will assume that a redirect from http to https is done in this way

server {
    listen 80;
    server_name example.com;
    return 301 https://$server_name;
}

And the redirect address should be like this https://$server_name$request_uri
. This is if you guess. If you need some specifics, then lay out the entire config - you need to look at what is twisted there.
PS. And what is the CMS?

D
Dmitry, 2018-08-08
@q2digger

Try like this.

location / {
        try_files $uri $uri/ /index.php;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question