http到https重写规则不起作用

时间:2013-04-24 11:16:34

标签: apache mod-rewrite https

我需要使用https在网站上投放表单。假设这是表单url:

http://www.mysite.com/cms/visit/residents/form

并且请求需要到这里:

https://www.mysite.com/cms/visit/residents/form

我在共享主机上,所以我把它放在根目录下的.htaccess文件中:

RewriteCond %{HTTPS} !=on
RewriteRule ^(cms/visit/residents/form.*)$ https://www.mysite.com/$1 [R=301,L]

这在我们的开发服务器(Apache / Debian Squeeze)上工作正常,但是当我将.htaccess文件置于实际状态时规则不起作用。 Rewrite Engine已启用且工作正常,因为.htaccess文件中已有其他重写和重定向。这些其他规则仍然可行。我已经问过这里主持网站的IT人员,他们不明白为什么规则不起作用。我已尝试过上述规则的无数变化,但无法在实时服务器上运行。这是我尝试的另一个例子:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^cms/visit/residents/form(.*) https://www.mysite.com/cms/visit/residents/form$1 [R=301,L]

我可以从开发服务器上的页面重写到实时服务器上的https url,所以我不认为目标是个问题。我能想到的是,在实时服务器上存在与Apache配置文件的交互,其中包含:

<VirtualHost *:80>
 ServerName www.mysite.com
 RewriteEngine on
 RewriteOptions inherit
 RewriteCond %{HTTP_HOST} !=www.mysite.com
 RewriteCond %{HTTP_HOST} !=""
 RewriteRule (.*) $1 [R=permanent,L]
</VirtualHost>
<VirtualHost *:443>
 ServerName www.mysite.com
 RewriteEngine on
 RewriteOptions inherit
 RewriteCond %{HTTP_HOST} !=www.mysite.com
 RewriteCond %{HTTP_HOST} !=""
 RewriteRule (.*) $1 [R=permanent,L]
 SSLEngine on
</VirtualHost>

有没有人有任何想法?我一直在为每个测试清除浏览器缓存,并检查.htaccess文件是否已正确上传。

.htaccess文件:

AddDefaultCharset utf-8
AddType text/x-component .htc
AddType application/x-httpd-php .php .phtml
DirectoryIndex index.html index.php redirect.php index.htm
Options -Indexes +Includes +ExecCGI

ErrorDocument 404 /not-found.html 
ErrorDocument 401 /access-error.html

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(cms/visit/residents/form.*)$ https://www.mysite.com/$1 [R=301,L]

# To tidy up urls of pages run by live Drupal install (under /cms)
RewriteRule (^research/events/patronage.*) cms/$1 [L]
RewriteRule (^intranet/facilities/meeting-rooms/supervision-room-booking) cms/$1 [L]
RewriteRule (^intranet/facilities/meeting-rooms/function-room-booking) cms/$1 [L]
RewriteRule (^study/five-question-feedback-form) cms/$1 [L]
RewriteRule (^intranet/students/graduates/ballot-form) cms/$1 [L]
RewriteRule (^intranet/students/graduates/summer-rooms) cms/$1 [L]
RewriteRule (^intranet/students/undergrads/accommodation/survey) cms/$1 [L]
RewriteRule (^intranet/students/grads/accommodation/survey) cms/$1 [L]
RewriteRule (^graduate-accommodation) cms/$1 [L]
RewriteRule (^undergraduate-accommodation) cms/$1 [L]
RewriteRule (^intranet/students/easter-vacation) cms/$1 [L]
RewriteRule (^students/grads/accommodation/ballot.html) cms/$1 [L]
RewriteRule (^students/undergrads/accommodation/ballot.html) cms/$1 [L]
RewriteRule (^intranet/students/advent-booking) cms/$1 [L]
RewriteRule (^intranet/students/christmas-vacation) cms/$1 [L]
RewriteRule (^intranet/students/undergrads/summer-vacation) cms/$1 [L]
RewriteRule (^six-question-survey) cms/$1 [L]
RewriteRule (^conference-dining/feedback) cms/$1 [L]
RewriteRule (^intranet/meat-free) cms/$1 [L]
RewriteRule (^conference-dining/enquiry-form) cms/$1 [L]
RewriteRule (^study/undergraduate/open-days/booking-form) cms/$1 [L]
RewriteRule (^study/undergraduate/open-days/arts-form) cms/$1 [L]
RewriteRule (^study/undergraduate/open-days/sciences-form) cms/$1 [L]
#RewriteRule (^intranet/college.*) cms/$1 [L]

# For the Cognitive Studies course 2012-13
Redirect permanent /cognitive http://mysite.com/intranet/students/cognitive-skills.html

(重写的疯狂数量,我知道,我应该将其压缩成一条规则!)

0 个答案:

没有答案