Is it possible to apply rewrite first and then Deny/Apply IP block with .htaccess? -


is possible apply redirect before deny/allow ip blocking .htaccess file?

i tried following, instead of redirect users not whitelisted blocked means deny/allow part executed should redirected. redirect part working fine tested without ip blocking. expected [l] flag in rewrite "stop" .htaccess execution before reaching ip blocking part.

rewritecond %{http_host} !^blog\.mysite\.com$ [nc] rewriterule (.*) http://www.mysite.com [l,nc,r=301]  order deny,allow deny allow xxx.xxx.xxx.xxx  rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ /index.php?/$1 [l] 

why i'm doing because should protect access http://www.mysite.com/blog while still showing same 404 shown site other invalid pages. if doing ip block first cannot show same 404 page generated site framework.

am doing wrong or not possible this?

you use rewrite condition check ip address:

rewriteengine on rewritebase /  #always redirect blog.mysite.com www.mysite.com rewritecond %{http_host} ^blog\.mysite\.com$ [nc] rewriterule (.*) http://www.mysite.com [l,nc,r=302]  #don't redirect if accessdenied.php page accessed rewritecond %{request_filename} ^accessdenied\.php$ rewriterule (.*) - [l]  #redirect not whitelisted ips rewritecond %{remote_addr} !^111\.111\.111\.111 [or] rewritecond %{remote_addr} !^222\.222\.222\.222 rewriterule (.*) accessdenied.php [r=302,l]  #only whitelisted ips use rewrite rule rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule (.*) index.php?/$1 [l,r=302] 

if ip matches, second rewrite rule not met, nothing happen. if ip doesn't match, user redirected 404 error page.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -