Rewrite rules for Nginx

B
  • 9 Nov '22
Hello

I am just moving my website from apache to nginx.

Unfortunately none of the online converters helped me with dealing the
htaccess migration to nginx rewrite rules.

Can someone help me with rewriting the correctly please?

Options +FollowSymlinks 
RewriteEngine On
ServerSignature Off
RewriteRule ^news/(.*)/([0-9]+)\/?$ home/read-news/$1/$2 [NC,L]
RewriteRule ^character/(.*)/(.*)\/?$ info/character/$1/$2 [NC,L]
RewriteRule ^guild/(.*)/(.*)\/?$ info/guild/$1/$2 [NC,L]
RewriteRule ^vote-reward\/?$ account-panel/vote-reward [NC,L]
RewriteRule ^account-logs\/?$ account-panel/logs [NC,L]
RewriteRule ^settings\/?$ account-panel/settings [NC,L]
RewriteRule ^logout\/?$ account-panel/logout [NC,L]
RewriteRule ^login\/?$ account-panel/login [NC,L]
RewriteRule ^reset-character\/?$ account-panel/reset [NC,L]
RewriteRule ^grand-reset-character\/?$ account-panel/grand-reset [NC,L]
RewriteRule ^add-stats\/?$ account-panel/add-stats [NC,L]
RewriteRule ^add-stats/(.*)\/?$ account-panel/add-stats/$1 [NC,L]
RewriteRule ^reset-stats\/?$ account-panel/reset-stats [NC,L]
RewriteRule ^hide-character-info\/?$ account-panel/hide-info [NC,L]
RewriteRule ^exchange-wcoins\/?$ account-panel/exchange-wcoins [NC,L]
RewriteRule ^warp-char\/?$ account-panel/warp-char [NC,L]
RewriteRule ^pk-clear\/?$ account-panel/pk-clear [NC,L]
RewriteRule ^clear-inventory\/?$ account-panel/clear-inventory [NC,L]
RewriteRule ^zen-wallet\/?$ account-panel/zen-wallet [NC,L]
RewriteRule ^clear-skilltree\/?$ account-panel/clear-skilltree [NC,L]
RewriteRule ^logs\/?$ account-panel/logs [NC,L]

RewriteCond %{REQUEST_URI} system.*
RewriteRule ^(.*)$ index.php [L]
RewriteCond %{REQUEST_URI} application.*
RewriteRule ^(.*)$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*) index.php?action=$1 [QSA,L]

<FilesMatch "(?:license\.txt)$">
Order allow,deny
Deny from all
</FilesMatch>

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,295707,295707#msg-295707
S
  • 12 Nov '22
Hi,

hope you're doing well.

On Wed, Nov 09, 2022 at 03:59:22PM -0500, Bumb1ebe wrote:
> 
> I am just moving my website from apache to nginx.
> 
> Unfortunately none of the online converters helped me with dealing the
> htaccess migration to nginx rewrite rules.
> 
> Can someone help me with rewriting the correctly please?
> 
> RewriteRule ^news/(.*)/([0-9]+)\/?$ home/read-news/$1/$2 [NC,L]

Here's the explanation about apache 2.4 flags for RewriteRules [1].
In a few words:
- NC means match in a case-insensitive manner;
- L means stop processing the rule set.

Then please take a look on NGINX documentation site [2].
The following link to the rewrite directive contains very good,
example, [3].  It's very closer to what you want to implement.

Also, please take a look on the location directive [4], it
helps understand how to route a request to a location.

References
1. https://httpd.apache.org/docs/2.4/rewrite/flags.html
2. https://nginx.org/en/docs
3. https://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite
4. http://nginx.org/en/docs/http/ngx_http_core_module.html#location

Hope that helps.

-- 
Sergey A. Osokin