重写所有URL到SSL除了与Zend框架特定的文件夹 [英] Rewrite all URL to SSL except specific folders with Zend Framework

查看:201
本文介绍了重写所有URL到SSL除了与Zend框架特定的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于事先的任何帮助。
我有Zend框架的设置我们的Web应用程序,并已使用基本SSL重定向到现在工作得很好。我们希望所有重定向URL对SSL,除了一对夫妇的路径。一条路径工作正常,只是加载图像文件。但是其他的路径不,它是一个Zend框架控制器需要请求参数的动作。

下面是我们的电流,工作配置:

  RewriteEngine叙述在
的RewriteCond%{} HTTPS!=上
的RewriteCond%{REQUEST_URI}!(/图片)
重写规则^ https://开头%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]的RewriteCond%{} REQUEST_FILENAME -s [OR]
的RewriteCond%{} REQUEST_FILENAME -l [OR]
的RewriteCond%{} REQUEST_FILENAME -d
。重写规则^ * $ - [NC,L]
重写规则^ * $的index.php [NC,L]

以上作品的图像除外,并允许ZF工作,但我们想在URI路径/ wsrv /的ItemData也排除任何东西
我们尝试使用此条件:

 的RewriteCond%{REQUEST_URI}!(/ wsrv /的ItemData)

/ wsrv /的ItemData可能包括这种格式的几个参数:

  / wsrv /的ItemData / item_nbr / 111111 / some_other_arg / a值

我们的问题是,它总是重定向到的index.php,它被引导到SSL。我们需要重定向到index.php为框架的功能,但不使用SSL只为单控制器和动作/ wsrv /的ItemData。

我AP preciate任何帮助。谢谢!

修改12年6月4日:(!解决大部分)
它不是URL重写,它在我的装载机Zend框架的东西。我添加的规则之下,用一些测试文件,规则工作。但是东西在我的框架设置被重定向的。

 的RewriteCond%{} HTTPS!=上
的RewriteCond%{REQUEST_URI}!(/图像/)
的RewriteCond%{REQUEST_URI}!(/ wsrv /的ItemData /)
的RewriteCond%{REQUEST_URI}!(/测试/制造/)
重写规则^ https://开头%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]的RewriteCond%{} REQUEST_FILENAME -s [OR]
的RewriteCond%{} REQUEST_FILENAME -l [OR]
的RewriteCond%{} REQUEST_FILENAME -d
。重写规则^ * $ - [NC,L]
重写规则^ * $的index.php [NC,L]

上面的作品,除了/ wsrv /的ItemData线,这是通过框架去


解决方案

我找到了解决我的问题。
该课题通过发布其他用户的帮助,被有关,但我不能让他的解决方案的工作:

<一个href=\"http://stackoverflow.com/questions/6580154/htaccess-https-redirect-only-on-specific-zend-frameworks-controller-actions\">htaccess HTTPS仅在特定的Zend框架控制器/动作重定向

我的解决办法的工作,除一个问题,它前进的脚步并没有prevent我。下面列出的重写规则允许我省略了在特定的Zend框架控制器和操作方法SSL连接,同时迫使别的不存在正常使用SSL连接。 (基本上,强制所有SSL,但一个路径)

的唯一例外此溶液中发送的URL/尾随。如果我没有在结尾的斜线发送时,它仍然会自动转发我的index.php。因为我需要反正传递的参数,最后的斜线是存在的,所以对我的作品。
工作原理:/ wsrv /的ItemData /
作品:/ wsrv /的ItemData / item_nbr / 123456 / otherarg / otherval
不工作:/ wsrv /的ItemData

下面是最终的,复杂的重写规则:

  RewriteEngine叙述在#如果REQ是正常的文件,目录
#then传递要求不变(显示CSS,JS,IMG等,没有ZF)
#do不PROC更多的规则
的RewriteCond%{} REQUEST_FILENAME -s [OR]
的RewriteCond%{} REQUEST_FILENAME -l [OR]
的RewriteCond%{} REQUEST_FILENAME -d
。重写规则^ * $ - [NC,L]#如果REQ是SSL
#不wsrv /的ItemData
#而不是图像
#和没有测试/制造
#然后重新REQ到index.php使用ZF
#do不PROC更多的规则
的RewriteCond%{} HTTPS上
的RewriteCond%{REQUEST_URI}!wsrv /的ItemData /
的RewriteCond%{REQUEST_URI}!图片/
的RewriteCond%{REQUEST_URI}!测试/制造/
重写规则^ * $的index.php [L]#NOTE:的ItemData /必须有尾随/客户端requsts
#换句话说,请求/ wsrv /的ItemData会重定向到指数
#我不知道如何解决这个问题还没有
#但是/总是无论如何使用,因为要求ARG游戏使用
#例如:/ wsrv /的ItemData / item_nbr / 12345678#如果REQ不是SSL
#我们希望wsrv /的ItemData /
#then重写没有SSL采埃孚的index.php
#do不PROC更多的规则
的RewriteCond%{} HTTPS!=上
的RewriteCond%{REQUEST_URI} wsrv /的ItemData /
重写规则^ * $的index.php [L]#最后如果没有以上的比赛,检查非SSL
#如果REQ是SSL
#不wsrv /的ItemData
#而不是图像
#和没有测试/制造
#然后重定向到https://使用同一个URI
#do不PROC更多的规则
的RewriteCond%{} HTTPS!=上
的RewriteCond%{REQUEST_URI}!wsrv /的ItemData /
的RewriteCond%{REQUEST_URI}!图片/
的RewriteCond%{REQUEST_URI}!测试/制造/
重写规则^ https://开头%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]

thanks in advance for any help. I have Zend Framework setup for our web app, and has worked fine using a basic SSL redirect until now. We'd like to redirect all URL's to SSL, except a couple paths. One path works fine and is just loading image files. But the other path does not, and it is a Zend Framework Controller with an Action requiring request arguments.

Here's our current, working config:

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]

The above works for excluding images and allowing ZF to function, but we'd like to also exclude anything in the URI path /wsrv/itemdata and we tried using this condition:

RewriteCond %{REQUEST_URI} !(/wsrv/itemdata)

/wsrv/itemdata may include several parameters in this format:

/wsrv/itemdata/item_nbr/111111/some_other_arg/a-value

Our problem is that it always redirects to /index.php, which is directed to SSL. We need the redirect to index.php for the framework to function, but not using ssl for only the single controller and action /wsrv/itemdata.

I appreciate any help. Thanks!

EDIT 6-4-12: (SOLVED! mostly) Its not the URL rewriting, its something in my loader for Zend Framework. I added the rules below and used some test files, the rules work. But something in my framework setup is redirecting it.

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]

The above works, except for the /wsrv/itemdata line, which is going through the framework.

解决方案

I found a solution to my problem. This Question posted by another user helped and was related, but I couldn't get his solution to work:

htaccess https redirect only on specific Zend Frameworks controller/actions

My solution worked, except one issue, which didn't prevent me from moving forward. The rewrite rules listed below allow me to omit SSL connection under specific Zend Framework controller and action methods, while forcing anything else not existing to use normal SSL connections. (basically, force everything SSL, but one path)

The only exception to this solution was the trailing "/" in the URL sent. If I do not send in the trailing slash, it will still auto-forward me to index.php. Since I need arguments passed in anyway, the trailing slash is there, so works for me. Works: /wsrv/itemdata/ Works: /wsrv/itemdata/item_nbr/123456/otherarg/otherval Not work: /wsrv/itemdata

Here's the final, complicated rewrite rules:

    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]

这篇关于重写所有URL到SSL除了与Zend框架特定的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆