0

我需要使用 https 在网站上提供表格。假设这是表单网址:

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 文件置于活动状态时,该规则不起作用。重写引擎已打开并且工作正常,因为 .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

(我知道,大量的重写,我应该浓缩成一条规则!)

4

0 回答 0