2014-02-21 28 views
0

我有一個REST API由apache2在www.mysite.com服務。只允許訪問特定的mod_rewrite生成的URL,拒絕所有其他http請求

的REST API是www.mysite.com/rest訪問/ ...

但是沒有命名在包裝盒上,所有被重寫規則發生/休息文件夾。

如何才能實現後續的使用.htaccess文件:

1)允許訪問的所有請求來www.mysite.com/rest/...(即任何要求,只要它是子到虛擬文件夾/休息)

2)只允許來自特定IP地址的任何其他請求,例如虛構IP 123.45.67.89;對於所有其他IP地址,拒絕

原因是我不想讓任何人登陸www.mysite.com上的管理頁面。

謝謝你的httpd.conf的

內容如下:

<Directory "/opt/bitnami/apps/myapp/htdocs/web"> 
Options -Indexes +FollowSymLinks -MultiViews 
AllowOverride None 

<IfVersion <2.3> 
Order allow,deny 
Allow from All 
</IfVersion> 
<IfVersion >= 2.3> 
Require all granted 
</IfVersion> 
        <IfModule pagespeed_module> 
        ModPagespeedDisallow "*" 
        </IfModule> 
RewriteEngine on 
RewriteBase/

# Force login to be SSL 
RewriteCond %{HTTPS} !=on 
RewriteCond %{HTTP_HOST} ^(.+)\.cloud\.myapp\.com$ [NC] 
RewriteRule ^/?web/login/?(.*) https://%{SERVER_NAME}/web/login/$1 [R,L] 

# if ack directory or a file exists, use it directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php 
RewriteRule ^.*$ /index.php [L] 
### END: .htaccess inline ### 

<LimitExcept GET HEAD PUT DELETE PATCH POST> 
    Allow from all 
</LimitExcept> 

<IfDefine USE_PHP_FPM> 
    RewriteEngine On 
    RewriteOptions Inherit 

    RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fopt%2fbitnami%2fphp%2fvar%2frun%2fmyapp.sock/%{REQUEST_FILENAME} [P,L] 
</IfDefine> 

包括 「/opt/bitnami/apps/myapp/conf/htaccess.conf」

+0

發佈您當前的htaccess規則。 –

+0

我這樣做是爲了編輯原文。 – user1729972

+0

@PanamaJack:我現在已經添加了一些指令,可以正確檢測出IP是不是123.45.67.89,但是它錯誤地拒絕訪問包括/ rest /下的任何內容...... 我有RewriteCond%{REQUEST_FILENAME}!rest/....然後.... RewriteRule ^(。+)/ tmp/$ 1 [L] 我需要什麼小小的調整? – user1729972

回答

0

試試並取代此

<IfVersion <2.3> 
Order allow,deny 
Allow from All 
</IfVersion> 
<IfVersion >= 2.3> 
Require all granted 
</IfVersion> 

下面看看它是如何工作的。

Order deny,allow 
Deny from all 
Allow from 123.456.67.89 

您的IP地址替換123.456.67.89 IP地址

然後加入下另一個用於/休息夾另一個目錄指令。

<Directory /opt/bitnami/apps/myapp/htdocs/web/rest> 
Order Allow,Deny 
Allow from All 
</Directory> 

這是如何工作的。同樣,你也可以在root和/ rest中使用htaccess。

+0

這具有給予所有人403條禁止消息的效果,包括被授予的IP地址。所有請求都會發生這種情況,/休息包容。請記住,沒有物理文件夾與../rest所以目錄指令真的在.conf中工作?如果這是原因,我該如何將這些轉換成htaccess重寫指令。 – user1729972

相關問題