Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework 通过URL重写强制特定的Zend Framework控制器_Zend Framework_Mod Rewrite - Fatal编程技术网

Zend framework 通过URL重写强制特定的Zend Framework控制器

Zend framework 通过URL重写强制特定的Zend Framework控制器,zend-framework,mod-rewrite,Zend Framework,Mod Rewrite,在Zend Framework(v1.12)应用程序中,我希望强制调用特定的控制器(api) 我已经设法重写了任何请求,因此无论请求是什么(例如“或”),它都被重写为。。。(例如“或”)具有以下Apache重写规则: <VirtualHost *:80> [...] RewriteEngine On RewriteCond %{REQUEST_URI} !^/?api/?.* [NC] RewriteCond %{REQUEST_URI} !^/ind

在Zend Framework(v1.12)应用程序中,我希望强制调用特定的控制器(
api

我已经设法重写了任何请求,因此无论请求是什么(例如“或”),它都被重写为。。。(例如“或”)具有以下Apache重写规则:

<VirtualHost *:80>
    [...]
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/?api/?.* [NC]
    RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
    RewriteRule ^/?(.*)$ /api/$1 [R,L]
    [...]
</VirtualHost>
但这仍然允许用户通过访问应用程序的主页,我无法阻止这一点

我试图阻止:

<VirtualHost *:80>
    [...]
    # Rewrite code from above
    [...]
    <Location /index.php>
        Order Allow,Deny
        Deny from all
    </Location>
    [...]
</VirtualHost>
因此,对于每个请求,我都会得到一个“禁止-您无权访问此服务器上的/index.php”

当用于重写请求时,我是否可以允许访问“index.php”,并禁止直接访问它


我确信这可以由ZF应用程序的路由器完成,但希望避免更改应用程序的PHP源代码。

使用
ENV:REDIRECT_STATUS
变量(请参见“我已成功禁止直接访问
index.PHP
”:

RewriteEngine On

# Force controller "api"
RewriteCond %{REQUEST_URI} !^/?api/?.* [NC]
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^/?(.*)$ /api/$1 [R,L]

# Deny direct access to "index.php"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule index\.php$ - [NC,F]
测试用例:

  • 得到一个403
  • 得到一个302到
  • 得到一个302到
  • 得到200分
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteEngine On

# Force controller "api"
RewriteCond %{REQUEST_URI} !^/?api/?.* [NC]
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^/?(.*)$ /api/$1 [R,L]

# Deny direct access to "index.php"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule index\.php$ - [NC,F]