Score:0

Convert .htaccess rules to nginx format

cn flag

I bought a ready-made Laravel script that was developed to run on Apache server, and the developer doesn't support to Nginx rewrite rules. Can someone help me? When I try to access the system on my Nginx server it gives multiple redirects error. I've tried it in several ways and I can't, I even used online converters, but it doesn't work.

This is the original .htaccess from the script:

DirectoryIndex index.php
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On
    <IfModule mod_ssl.c>
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    </IfModule>

    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    RewriteCond %{THE_REQUEST} /index\.php/(.+)\sHTTP [NC]
    RewriteRule ^ /%1 [NE,L,R]
    
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^ index.php [L]
    
</IfModule>
kz flag
_Aside:_ That last rule is a bit unusual... it would result in requests for any physical resources, that do not contain `/public/` at the start of the URL-path also being routed to the Laravel front-controller. Ordinarily, `/public/` shouldn't be in the public URL-path to begin with, so this potentially means that every request is sent through the front-controller. Is that the intention? Is this like a members-only site where _every_ request must be authenticated or something?
user3416348 avatar
cn flag
yes, the script is a backend for an android app
djdomi avatar
za flag
why not install apache and use the native way? apache can run on a different port?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.