Forum Moderators: phranque

Message Too Old, No Replies

How to transfer .htaccess code to nginx code, pls?

         

yisou

9:00 am on Jul 24, 2021 (gmt 0)

10+ Year Member Top Contributors Of The Month


RewriteCond %{REQUEST_URI} ^/(index.php/)?admin(.*) [NC]
RewriteCond %{REMOTE_ADDR} !^10\.1\.1\.10
RewriteCond %{REMOTE_ADDR} !^10\.1\.1\.12
RewriteRule .* - [F,L]

tks.

phranque

11:15 pm on Jul 31, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



a few comments about the apache directives used here before we should talk about nginx application of those:

- REQUEST_URI contains only the path info and not the query string (i.e., it stops before the '?')
- the '(.*)' in the first RewriteCond directive isn't necessary or helpful - you aren't subsequently using that capture group anywhere.
- the final two RewriteCond directives should be end-anchored or they may match IP addresses you weren't intending (such as 10.1.1.100 or 10.1.1.101 etc)
- the final two RewriteCond directives could be combined into a single directive:
RewriteCond %{REMOTE_ADDR} !^10\.1\.1\.1[02]$

lucy24

1:02 am on Aug 1, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



(i.e., it stops before the '?')
I don't think that's a literal ? but a RegEx ? meaning the "index.php/" componenet is optional. But is that really what the URLs look like?
example.com/index.php/adminblahblah
or did you mean to say
^/(index\.php/|admin)
?

Incidentally, I don't think [NC] is warranted here. If they're legitimate requests, they will have the casing right, so why put the server to extra work.

Oh, and [F] implies [L], so you can save yourself two bytes, The superfluous ,L will do no harm; it simply isn't needed.

phranque

8:44 pm on Aug 1, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I don't think that's a literal ?

brain fart on my part...