2016-11-16 152 views
0

我想限制Apache訪問我的Laravel 5.3應用程序。Laravel .htaccess rewrite和apache2位置指令

我的應用程序在內部可用,但從各種外部來源接收回貼。有一個端口轉發設置禁用NAT,所以我可以告訴內部來自外部請求。

除非example.com/api/external/ ...是URL,否則所有網址都應顯示403。我有以下htaccess的(默認的Laravel 5.3)

<IfModule mod_rewrite.c> 
<IfModule mod_negotiation.c> 
    Options -MultiViews 
</IfModule> 

RewriteEngine On 

# Redirect Trailing Slashes If Not A Folder... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

# Handle Front Controller... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [L] 

# Handle Authorization Header 
RewriteCond %{HTTP:Authorization} . 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

我的虛擬主機配置

<Directory /var/www/mailer/public/> 
      Options Indexes FollowSymLinks 
      AllowOverride All 
      Require all granted 
    </Directory> 

    <Location /> 
      Order deny,allow 
      deny from all 
      allow from 10.64.1.0/24 
      allow from 10.64.20.0/24 
    </Location> 

    <Location /api/external/smsPost> 
      Allow from all 
    </Location> 

每當我從一個外部地址訪問任何URL我仍然得到403即使在允許的位置。

You don't have permission to access /index.php on this server. 

我想是因爲它有它與htaccess的和不工作的這一目的位置指令問題的index.php甚至example.com/api/external/smsPost。有什麼辦法可以達到我需要的這個指令嗎?

非常感謝。

回答

0

爲什麼不使用laravel中間件並將其綁定到受限制的路由?

public function handle($request, Closure $next) 
{ 

    if(Route::getCurrentRoute()->getPath() == "api/external/") 
      return response('You don't have permission to access /index.php on this server.', 403); 

    // return the $next closure, so other Middlewares can run 
    return $next($request); 
}