Php 使用Zend Framework将除特定文件夹外的所有URL重写为SSL

Php 使用Zend Framework将除特定文件夹外的所有URL重写为SSL,php,zend-framework,mod-rewrite,apache2,Php,Zend Framework,Mod Rewrite,Apache2,提前感谢您的帮助。 我已经为我们的web应用程序安装了Zend Framework,并且使用基本的SSL重定向到目前为止工作得很好。我们希望将所有URL重定向到SSL,除了几个路径。一个路径可以正常工作,只是加载图像文件。但另一条路径没有,它是一个Zend Framework控制器,其操作需要请求参数 这是我们当前的工作配置: RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{REQUEST_URI} !(/images) Rewr

提前感谢您的帮助。 我已经为我们的web应用程序安装了Zend Framework,并且使用基本的SSL重定向到目前为止工作得很好。我们希望将所有URL重定向到SSL,除了几个路径。一个路径可以正常工作,只是加载图像文件。但另一条路径没有,它是一个Zend Framework控制器,其操作需要请求参数

这是我们当前的工作配置:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !(/images)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
上面用于排除图像并允许ZF工作,但我们也希望排除URI路径/wsrv/itemdata中的任何内容 我们尝试使用这个条件:

RewriteCond %{REQUEST_URI} !(/wsrv/itemdata)
/wsrv/itemdata可能包括以下格式的几个参数:

/wsrv/itemdata/item_nbr/111111/some_other_arg/a-value
我们的问题是,它总是重定向到/index.php,而/index.php则指向SSL。我们需要重定向到index.php以使框架正常工作,但不能仅对单个控制器和action/wsrv/itemdata使用ssl

谢谢你的帮助。谢谢

编辑6-4-12:已解决!主要地 这不是URL重写,而是我的Zend框架加载程序中的内容。我在下面添加了规则,并使用了一些测试文件,这些规则很有效。但在我的框架设置中,有些东西正在重定向它

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !(/images/)
RewriteCond %{REQUEST_URI} !(/wsrv/itemdata/)
RewriteCond %{REQUEST_URI} !(/test/make/)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

除了通过框架运行的/wsrv/itemdata行之外,上面的操作都是有效的。

我找到了解决问题的方法。 另一个用户发布的这个问题有帮助且相关,但我无法让他的解决方案起作用:

我的解决方案奏效了,但有一个问题并没有阻止我前进。下面列出的重写规则允许我省略特定Zend Framework控制器和操作方法下的SSL连接,同时强制其他不存在的东西使用普通SSL连接。基本上,强制所有SSL,但只有一条路径

此解决方案的唯一例外是发送的URL中的尾随/字符。如果我不发送尾随斜杠,它仍然会自动将我转发到index.php。因为我需要传入参数,后面的斜杠就在那里,所以对我来说很有用。 工作:/wsrv/itemdata/ 工作:/wsrv/itemdata/item_nbr/123456/otherarg/otherval 不工作:/wsrv/itemdata

下面是最后一条复杂的重写规则:

    RewriteEngine On

#if req is normal file, dir
#then pass in request unchanged (show css, js, img, etc, no ZF)
#do not proc more rules
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

#if req is ssl
#   and not wsrv/itemdata
#   and not images
#   and not test/make
# then rewrite req to index.php to use ZF
#do not proc more rules
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !wsrv/itemdata/
RewriteCond %{REQUEST_URI} !images/ 
RewriteCond %{REQUEST_URI} !test/make/ 
RewriteRule ^.*$ index.php [L]

#NOTE: itemdata/ must have trailing / in client requsts
# In other words, requesting /wsrv/itemdata will redirect to index
# I don't know how to fix that yet
# But / is always used anyway because request args are used
# Ex: /wsrv/itemdata/item_nbr/12345678

#if req is NOT ssl
#   and we want wsrv/itemdata/
#then rewrite without ssl to ZF index.php
#do not proc more rules
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} wsrv/itemdata/
RewriteRule ^.*$ index.php [L]

# Last if none above match, check for non-ssl
#if req is ssl
#   and not wsrv/itemdata
#   and not images
#   and not test/make
# then REDIRECT to https:// using same URI
#do not proc more rules
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !wsrv/itemdata/
RewriteCond %{REQUEST_URI} !images/ 
RewriteCond %{REQUEST_URI} !test/make/ 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]