.htaccess - htaccess rewrite exclusion not working -


i have issue have been struggling on hours now. can't seem work how want too. put, want redirect url requests www.test.com.au except ip addresses below or request has "/unsubscribe/" in url.

the ip address exclusions work perfectly. however, trying reach example www.test.com.au/flashsale/newsletter/subscriber/unsubscribe/id/8255/code/7iji5wv5hs8e3klvwwltlqy2bjmpmg5f/ redirects / everytime , not want to.

here broken rewrite rule

rewritecond %{remote_addr} !^110\.174\.129\.147 rewritecond %{remote_addr} !^203\.217\.17\.162 rewritecond %{remote_addr} !^111\.67\.4\.233 rewritecond %{request_uri} !/unsubscribe/ [nc] rewritecond %{request_uri} !^/$ [nc] rewritecond %{request_uri} !\.(jpe?g?|png|gif) [nc] rewriterule .* / [r=301,l] 

where going wrong?

ps: killing me.

your file should this:

rewritecond %{request_uri} !/flashsale/newsletter/subscriber/unsubscribe/id/[\d]+/code/[a-z\d]+/? [nc] rewritecond %{remote_addr} !^110\.174\.129\.147 [or] rewritecond %{remote_addr} !^203\.217\.17\.162 [or] rewritecond %{remote_addr} !^111\.67\.4\.233 [or] rewritecond %{request_uri} !\.(jpe?g?|png|gif)$ [nc] rewriterule ^ / [r=301,l] 

explanation:

  1. the first change addition of or flag. original code did not have this. mod_rewrite automatically assume and flag, meant code checking ip addresses.

  2. the second change involved specifying full request_uri check, necessary wild cards. first wild card (\d) checks digits, whilst second 1 (a-z\d) checks both digits , characters 'a' 'z'.

edits:

i have made edit. have moved unsubscribe part top. ensure request not match given string, , of listed ip addresses not being used access request.

(please note not in testing environment @ moment. modifications not guaranteed work.)


Comments