Forum Moderators: phranque
I am going to open the site that includes admin-pages and
user pages.
Page uri is like as following.
User Pages : http://www.example.com/...
Admin Pages : http://www.example.com/admin/...
http://www.example.com/install/...
I want to restrict IP range for only administrative pages.
The following htaccess script is for my site.
In reference, My site is running on Zend Framework 1.8.
--------------------------------------------------------
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
--------------------------------------------------------
Please show me how to write .htaccess script for
restriction above.
Best regards.
[edited by: jdMorgan at 10:09 pm (utc) on June 17, 2009]
[edit reason] example.com [/edit]
I found the solution.
I allowed to access to admin pages from 192.168.15.121, 122.
I want to help the developers for this script.
----------------------------------------------------
RewriteCond %{REMOTE_ADDR} !^192\.168\.15\.121$
RewriteCond %{REMOTE_ADDR} !^192\.168\.15\.122$
RewriteCond %{REQUEST_URI} ^.*\/(admin¦install)\/.*$ [NC]
RewriteRule .* /error-403.php
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
--------------------------------------------------------
Thanks. Good day!
RewriteCond %{REMOTE_ADDR} !^192\.168\.15\.121$
RewriteCond %{REMOTE_ADDR} !^192\.168\.15\.122$
RewriteRule ^(admin¦install)/ - [F]
Jim
Your reply helped me with my .htaccess setting.
I have more problems.
-----------------------------------------------------------
RewriteCond %{HTTP_USER_AGENT} ^.*(MSIE¦Firefox¦Safari¦Opera¦Chrome).*$ [NC]
RewriteCond %{REQUEST_URI} !^.*\/(admin¦install)\/.*$ [NC]
RewriteRule ^.*$ - [F,L]
-----------------------------------------------------------
Script above is for blocking access to mobile pages from PC-browser.
Mobile pages are ones besides following.
http://www.example.com/dir/admin
http://www.example.com/dir/install
Mobile pages are like as;
http://www.example.com/dir/{sub paths}
But, the script doesn't bring to me any affect.
I think that the reason is because of (!)negative sign.
Please show me how to correct the script.
Best regards.
Removing unnecessary escaping and redundant patterns:
RewriteCond %{HTTP_USER_AGENT} (MSIE¦Firefox¦Safari¦Opera¦Chrome) [NC]
RewriteCond %{REQUEST_URI} !(admin¦install)/ [NC]
RewriteRule . - [F] Be aware that Opera make one of the most widely used Mobile Browsers on the planet, so you might need to review your list again.
>> [F] always implies [L]
>>
>> Removing unnecessary escaping and redundant patterns:
>>
>> RewriteCond %{HTTP_USER_AGENT} (MSIE¦Firefox¦Safari¦Opera¦Chrome) [NC]
>> RewriteCond %{REQUEST_URI} !(admin¦install)/ [NC]
>> RewriteRule . - [F]
I confirmed that [F] always implies [L].
And I tried with script above, but the negative sign(!) seems to be not working correctly yet.
If I deleted sign(!), the script would be working correctly, but inversely.
I think the key of resolution is in sign(!).
I am finding the resolution and looking forward your help.
Best regards.
Anyway, I have one suggestion.
How about skipping over ( RewriteRule .* - [F] ) line using [S=*] option?
---------------------------------------------------
RewriteCond %{HTTP_USER_AGENT} (MSIE¦...¦...) [NC]
RewriteRule (admin¦install) - [S=1] # If pc, skip blocking line and go to next lines.
RewriteRule .* - [F]
... some other scripts
---------------------------------------------------
However, I don't know about [S] option well.
Please teach me.
------------------------------------------------------
RewriteEngine on
# IP restriction for administrative pages
RewriteCond %{REMOTE_ADDR} !^192\.168\.25\..*$
RewriteCond %{REQUEST_URI} ^.*\/(admin¦install¦default)\/.*$ [NC]
RewriteRule ^.*$ - [F]
# Browser restriction for mobile pages
RewriteCond %{HTTP_USER_AGENT} (MSIE¦...¦...¦...) [NC]
RewriteCond %{REQUEST_URI} (admin¦install¦default) [NC]
RewriteRule .* - [S=1]
RewriteRule .* - [F]
# General rule for Zend Framework
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [NC,L]
RewriteRule .* index.php [NC,L]
------------------------------------------------------
IP restriction is working correctly.
I think the script for Zend FW is also correct.
Could you check script for browser restriction, please?
Best regards.