R
R
Romashenko2018-10-17 10:44:23
Nginx
Romashenko, 2018-10-17 10:44:23

Nginx Rewrite not working, how to solve?

Hello. There is a php script at the root is the .htaccess file and in the /router folder is the .htaccess file
The one that lies at the root :

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ router/ [L]
    RewriteRule (.*) router/$1 [L]
</IfModule>

The one in the /router directory :
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php [L]
</IfModule>

nginx default config :
serve<code></code>r {
  listen 80 default_server;
  listen [::]:80 default_server;
  
  root /home/vadosiq/server/public_html;
  index index.php index.phtml index.html index.htm;
  server_name _;
  location / {
    rewrite ^$ router/ break;
    rewrite ^(.*)$ router/$1 break;
    try_files $uri $uri = 404;
  }

  location /router {
    if (!-e $request_filename) {
       rewrite ^router/(.*)$ router/index.php break;
     } 
  }
  
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
  }	
  
  location ~ /\.ht {
    deny  all;
  }
}

Tried various online converters, nothing helped. Tell me what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Syomov, 2018-10-17
@kotomyava

It's better to understand how to configure, read the documentation, understand what needs to be done, and write a config, rather than mindlessly using converters...
The equivalent of your .htaccess would look something like this:

location = / {    
  rewrite ^$ router/;
}
location / {
    rewrite ^(.*)$ router/$1 break;
}
location /router {
   try_files $uri $uri/ /router/index.php;
}

Well, you probably don’t need to edit the default nginx config, but create a separate config for your domain. And let default respond with a stub, if it does not enter the domain, as it is done by default ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question