Score:0

rewrite rules from apache to nginx

cn flag

I have a problem with this... I'm using free hosting for giving a demo to my future buyers of my own cms.

The hosting is hubuhost.com, they are supporting the last version of php 8.1. The problem is that they are on nginx and do not support my htaccess rules from apache.

My config is :

<IfModule mod_negotiation.c>
#Important rules for our system
Options -Multiviews -Indexes +FollowSymLinks
</IfModule>

#app.php instead of index.php
<IfModule mod_dir.c>
DirectoryIndex core.php index.php index.html
</IfModule>

#If 404 - redirect to 404 page
ErrorDocument 404 /404/index.php

<IfModule mod_rewrite.c>
#ModRewrite ON
RewriteEngine on 

#News SEO Urls
RewriteRule  ^topic_(.+?)$ core.php?id=$1

#Router
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ core.php [QSA,L]
 
#remove end trailing slash from urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/$
RewriteRule ^ /%1 [R=301,L]
</IfModule>

#Block ENV access
<IfModule mod_version.c>
<Files "config.env">
   Order allow,deny
    Deny from all
</Files>
</IfModule>

Can someone convert this to nginx ?

I try with some rules but without success. I don't know what to do... Demo pic from admin panel: https://i.ibb.co/gwZStXN/image.png

kz flag
_Aside:_ The Apache mod_rewrite rules are not in the correct order. The rule `#remove end trailing slash from urls` is not doing anything. This needs to go _before_ the `#Router`.
Score:0
ng flag

See if this will do the job

autoindex off;

index core.php index.php index.html;

error_page 404 /404/index.php;

location /topic_ {
  rewrite ^/topic_(.+?)$ /core.php?id=$1;
}

location / {
  if (!-e $request_filename){
    rewrite ^(.*)$ /core.php break;
  }
  if (!-e $request_filename){
    rewrite ^(.*)$ /%1 redirect;
  }
}

location /config.env {
  deny all;
}
cn flag
thank you, but this is not supported by hosting (maybe), they allowed only a few rules....I will search for another free host provider.
Zhivko Zhelev avatar
ng flag
Welcome, what is the error you get?
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.