在https情况下忽略Apache RewriteCond
我必须从一个域重定向到另一个域。这两个域都启用了http和https协议。为了映射http和https,我在conf文件中尝试了各种组合,如下所示: #RewriteCond%{HTTPS}=on #重写cond%{SERVER_PORT}^443$ #重写规则^(+)$-[env=askapache:https]在https情况下忽略Apache RewriteCond,apache,.htaccess,mod-rewrite,https,Apache,.htaccess,Mod Rewrite,Https,我必须从一个域重定向到另一个域。这两个域都启用了http和https协议。为了映射http和https,我在conf文件中尝试了各种组合,如下所示: #RewriteCond%{HTTPS}=on #重写cond%{SERVER_PORT}^443$ #重写规则^(+)$-[env=askapache:https] #RewriteCond %{HTTPS} !=on #RewriteRule ^(.+)$ - [env=askapache:http] RewriteCond %{SERVER_
#RewriteCond %{HTTPS} !=on
#RewriteRule ^(.+)$ - [env=askapache:http]
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.+)$ - [env=askapache:%2]
RewriteCond %{HTTP_HOST} ^([www.]+)?test-redirect\.com$ [NC]
RewriteRule ^(.*)$ http%{ENV:askapache}//amit.test.com/content/test/category/6 [L]
#RewriteCond %{HTTP_HOST} ^([www.]+)?test-redirect\.com$ [NC] <BR>
#RewriteCond %{HTTPS} !on
#RewriteRule .? http://amit.test.com/content/test/category/6 [L]`
#重写cond%{HTTPS}=在…上
#重写规则^(+)$-[env=askapache:http]
重写cond%{SERVER_PORT}s^(443(s)|[0-9]+s)$
重写规则^(+)$-[env=askapache:%2]
重写cond%{HTTP_HOST}^([www.]+)?测试重定向\.com$[NC]
重写规则^(.*)$http%{ENV:askapache}//amit.test.com/content/test/category/6[L]
#重写cond%{HTTP_HOST}^([www.]+)?测试重定向\.com$[NC]
#重写cond%{HTTPS}!在…上
#重写规则。?http://amit.test.com/content/test/category/6 [L]`
但每次都会跳过/忽略https条件。也没有重写日志的功能。我在网上看到了很多例子。但不明白为什么它没有检测到https?http工作得非常好。- 对于https和http,重写日志很可能位于两个不同的位置。您可以尝试使用
而不是使用“askapache”作为环境名称。前缀HTTP_anywhere是一种更安全的方法,可以确保var可用,因为某些设置不允许自定义var以HTTP_以外的任何东西开头,因为HTTP_通常表示HTTP头HTTP_AA
- 确保您的https端口实际上是443,否则需要更改代码
- 通过尝试这里的第一个和第二个方法,确保您的mod_rewrite
代码可以工作:如果使用第一个示例无法工作,则需要首先使用该规则使其工作块
- 尝试使用SetEnvIfNoCase指令或使用
SetEnv HTTP_AA
- 验证SSL和非SSL的vhost/httpd.conf设置,如文档根目录和选项,以及SSLOptions的允许覆盖、日志和可能的stdenvvar
- 使用只执行
的printenv
构建shtml文件。然后查看ssl和非ssl输出,并特别注意前缀为mod\u includes
,显然要确保的var重定向
var在HTTP\u AA
输出中正确显示。或者您可以在askapache站点上使用cgi脚本或shtml示例printenv
- 别忘了
Options +FollowSymLinks +ExecCGI
# Set var now to try to try to have it availabe for mod_rewrite
SetEnv HTTP_AA
RewriteEngine On
RewriteBase /
# HTTP_AA is set to either s or is blank
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.+)$ - [env=HTTP_AA:%2]
# if host not new domain, its old so redirect both http/https to new
RewriteCond %{HTTP_HOST} !^amit\.example\.com$ [NC]
RewriteRule .* http%{ENV:HTTP_AA}://amit.example.com/content/test/category/6 [R=301,L]