简体   繁体   中英

Allow/Deny Access by IP to a Virtual/PHP Generated URL in .htaccess Without Apache Config Access

I've been trawling around, and theres many similar questions/answers, but none that fit, Or I'm searching for the wrong things

I'm using a PHP CMS, that routes the urls /admin/some-module

The /admin folder doesnt actually exist, as everything routes through an index.php bootloader.

I'm trying to effectively achieve

<Directory /admin>
    Order Deny,Allow
    Deny from all
    Allow from <some ip>
</Directory>

However it is on shared hosting which we cannot change the apache config to allow this.

How can you protect a url by IP from the root /public_html/.htaccess with the above setup?

I believe I'd do that in the index.php but in htaccess you could try this

RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4 [OR]
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.5
RewriteRule ^admin/ - [L,R=403]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM