将http重定向到https问题:网页显示混乱,反向重定向失败


Redirect http to https problems: webpage messy display and back-redirection fail

我们有一个网站,其主页是http://bigbird.comp.nus.edu.sg/pmwiki/farm/appl/index.php正如您所看到的,它是基于pmwiki的。它由Apache2托管。

我们想自动将登录页面(bigbird.comp.nus.edu.sg/pmviki/farm/appl/index.php?n=Site.login)从http重定向到https,但保持其他页面不变。

我所做的是修改/etc/apache2/httpd.conf

<VirtualHost *:80>
ServerName bigbird.comp.nus.edu.sg
DocumentRoot /var/www/
RewriteEngine On
RewriteOptions Inherit
/** ignore the following two lines. not related to the redirection **/
RewriteCond  %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule  .*favicon'.ico$         /var/www/favicon.ico [L]
/** Redirect to https only if the query string end with Site.Login **/
RewriteCond %{REQUEST_URI} /pmwiki/farm/appl/index.php$
RewriteCond %{QUERY_STRING} ^n=Site.Login$
RewriteRule ^.*$ https://bigbird.comp.nus.edu.sg/pmwiki/farm/appl/index.php?n=Site.Login [L,R=301]
</VirtualHost>

使用上面的代码,我们可以重定向登录页面。然而,登录页面的显示格式很混乱。另一个问题是,当我从登录页面跳到其他页面时,其他页面会重定向到https版本,它们的显示也会变得混乱。例如,单击页面左上角的"主页"链接。

我不知道显示器的问题。

我尝试通过添加以下代码将https请求重定向到其他页面的httpVirtualHost *:443段:

/** if query_string does not end with Site.Login, redirect it to http**/
RewriteCond %{QUERY_STRING} !^n=Site.Login&
RewriteRule ^.*$ http://%{HTTP_HOST}%{REQUEST_URI}%{QUERY_STRING} [L,R=301]

代码不起作用。我试过这里的模式,但也不起作用。

确保使用RewriteEngine On,并且不需要显式使用QUERY_STRING

RewriteEngine On
# if query_string does not end with Site.Login, redirect it to http
RewriteCond %{QUERY_STRING} !(^|&)n=Site'.Login(&|$)
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

由于%{QUERY_STRING}被自动转移到新的URL。