好了,我知道,几乎每一个品种这一问题已被要求,并回答了在这个论坛上,和许多其他人,但我似乎无法得到它的权利。我的希望是,如果我提供足够的细节,其中包括我在下面的过程中,会有人能够发现我的错误和指正。这里去!
的细节- Drupal的多站点
- Apache Web服务器
- 网站由Aegir置备
我想将所有HTTP和HTTPS流量,以 www.example 。标有下面的例子 + 已经完成;一个标有 - 躲开我:
- + example - > www.example
- + www.example - > www.example
- + www.example - > www.example #redundant,但至少我们知道它的工作原理
- - example - > www.example
每个站点都有所Aegir生成的虚拟主机文件,并且每个虚拟主机文件包含两个VirtualHost指令:
- <虚拟主机0.0.0.0:443>
- <虚拟主机*:80>
我修改 example 的虚拟主机文件包含在&LT以下code;虚拟主机*:80> 指令,它已成功地实现上述三个工作的例子:
< IfModule mod_rewrite.c> RewriteEngine叙述上 的RewriteCond%{HTTP_HOST} ^例如\\ $ .COM [NC] 重写规则HTTPS(*)://www.example$1 [R = 301,L] 的RewriteCond%{} HTTPS关闭 重写规则HTTPS(。*)://%{HTTP_HOST}%{REQUEST_URI}< / IfModule>问题
我似乎无法弄清楚是如何制定的 example - > www.example 重写。我都试过了℃在互联网上找到许多例子;虚拟主机0.0.0.0:443> 和<虚拟主机*:80> 没有运气指令。
另外,我重装Apache和虚拟主机文件的每个编辑后清除浏览器的缓存。任何见解,指导或纠正会大大AP preciated。
感谢所有!
编辑:下面是我的虚拟主机文件的删节版:
<虚拟主机0.0.0.0:443> DocumentRoot的/无功/网络/的Drupal 例如服务器名 SETENV db_type的mysql SETENV例如DB_NAME SETENV例如DB_USER SETENV db_passwd 1234567 SETENV DB_HOST somedb SETENV DB_PORT 1234 #启用SSL处理。 在SSLEngine的 了SSLCertificateFile /ssl.d/example/example.crt 了SSLCertificateKeyFile /ssl.d/example/example.key SSLCertificateChainFile /ssl.d/example/example_chain.crt ServerAlias example ServerAlias www.example< IfModule mod_rewrite.c> RewriteEngine叙述上 #这是不工作;既没有其他任何东西,我在这里尝试。 的RewriteCond%{HTTP_HOST} ^!WWW \\。 重写规则^ $ HTTPS(*)://www.% {} HTTP_HOST%{REQUEST_URI} [L,R = 301]< / IfModule> 从模块#额外的配置: 为Drupal&GT#错误处理程序; 4.6.7 <目录/无功/网络/的Drupal /网站/例子/文件> <文件*> SetHandler This_is_a_Drupal_security_line_do_not_remove < /文件> 选择无 选择了FollowSymLinks + #如果我们知道如何做到这一点安全,完全禁用PHP引擎。 < IfModule mod_php5.c> 的php_flag停机 < / IfModule> < /目录> #prevent私人DIR文件的直接读取。 #这是Drupal7的兼容性,这通常会下降 #在这些目录中的.htaccess,但我们明确地忽略这些 <目录/无功/网络/的Drupal /网站/例子/私营/> <文件*> SetHandler This_is_a_Drupal_security_line_do_not_remove < /文件> 所有拒绝 选择无 选择了FollowSymLinks + #如果我们知道如何做到这一点安全,完全禁用PHP引擎。 < IfModule mod_php5.c> 的php_flag停机 < / IfModule> < /目录> < /虚拟主机><虚拟主机*:80> DocumentRoot的/无功/网络/的Drupal 例如服务器名 SETENV db_type的mysql SETENV例如DB_NAME SETENV例如DB_USER SETENV db_passwd 1234567 SETENV DB_HOST somedb SETENV DB_PORT 1234 ServerAlias example ServerAlias www.example< IfModule mod_rewrite.c> #这些规则除一切工作: #example - > www.example 的RewriteCond%{HTTP_HOST} ^例如\\ $ .COM [NC] 重写规则HTTPS(*)://www.example$1 [R = 301,L] 的RewriteCond%{} HTTPS关闭 重写规则HTTPS(。*)://%{HTTP_HOST}%{REQUEST_URI}< / IfModule>从模块#额外的配置: 为Drupal&GT#错误处理程序; 4.6.7 <目录/无功/网络/的Drupal /网站/例子/文件> <文件*> SetHandler This_is_a_Drupal_security_line_do_not_remove < /文件> 选择无 选择了FollowSymLinks + #如果我们知道如何做到这一点安全,完全禁用PHP引擎。 < IfModule mod_php5.c> 的php_flag停机 < / IfModule> < /目录> #prevent私人DIR文件的直接读取。 #这是Drupal7的兼容性,这通常会下降 #在这些目录中的.htaccess,但我们明确地忽略这些 <目录/无功/网络/的Drupal /网站/例子/私营/> <文件*> SetHandler This_is_a_Drupal_security_line_do_not_remove < /文件> 所有拒绝 选择无 选择了FollowSymLinks + #如果我们知道如何做到这一点安全,完全禁用PHP引擎。 < IfModule mod_php5.c> 的php_flag停机 < / IfModule> < /目录>< /虚拟主机>解决方案
OK,现在我与你的虚拟主机的内容得到它。
这是无效的:
的RewriteCond%{HTTP_HOST} ^!WWW \\。重写规则^ $ HTTPS(*)://www.% {} HTTP_HOST%{REQUEST_URI} [L,R = 301]其实你不能使用%{HTTP_HOST} 或%{REQUEST_URI} 在重写规则部分
这就是为什么它重定向你到一个不存在的主机,因此拒绝连接错误。
您应该在SSL虚拟主机使用这样的规则:
RewriteEngine叙述上的RewriteCond%{HTTP_HOST} ^例如\\ $ .COM [NC]重写规则HTTPS(*)://www.example$1 [R = 301,L]而这一次在非SSL之一:
RewriteEngine叙述上的RewriteCond%{} HTTPS关闭重写规则HTTPS(*)://www.example$1 [R = 301,L]心连心
OK, so I know that nearly every variety of this question has been asked and answered on this forum, and many others, but I just can't seem to get it right. My hope is that if I provide enough specifics, including the process I'm following, that someone will be able to spot my error and correct me. Here goes!
The Specifics- Drupal multi-site
- Apache web server
- Sites provisioned by Aegir
I want to direct all http and https traffic to www.example. The following examples marked with a + have been accomplished; the one marked with - eludes me:
- + example -> www.example
- + www.example -> www.example
- + www.example -> www.example #redundant, but at least we know it works
- - example -> www.example
Each site has a vhost file generated by Aegir, and each of these vhost files contains two VirtualHost directives:
- <VirtualHost 0.0.0.0:443>
- <VirtualHost *:80>
I've modified example's vhost file to include the following code under the <VirtualHost *:80> directive, which has successfully achieved the three working examples above:
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^example\$ [NC] RewriteRule (.*) www.example$1 [R=301,L] RewriteCond %{HTTPS} off RewriteRule (.*) %{HTTP_HOST}%{REQUEST_URI} </IfModule>The Problem
What I can't seem to figure out is how to enact the example -> www.example rewrite. I've tried many examples found on the Internet under both the <VirtualHost 0.0.0.0:443> and <VirtualHost *:80> directives with no luck.
Also, I'm reloading Apache and clearing my browser's cache after each edit of the vhost file. Any insight, guidance or correction would be much appreciated.
Thanks to all!
Edit: Below is a redacted version of my vhost file:
<VirtualHost 0.0.0.0:443> DocumentRoot /var/www/drupal ServerName example SetEnv db_type mysql SetEnv db_name example SetEnv db_user example SetEnv db_passwd 1234567 SetEnv db_host somedb SetEnv db_port 1234 # Enable SSL handling. SSLEngine on SSLCertificateFile /ssl.d/example/example.crt SSLCertificateKeyFile /ssl.d/example/example.key SSLCertificateChainFile /ssl.d/example/example_chain.crt ServerAlias example ServerAlias www.example <IfModule mod_rewrite.c> RewriteEngine on # this isn't working; neither has anything else that I've tried here. RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] </IfModule> # Extra configuration from modules: # Error handler for Drupal > 4.6.7 <Directory "/var/www/drupal/sites/example/files"> <Files *> SetHandler This_is_a_Drupal_security_line_do_not_remove </Files> Options None Options +FollowSymLinks # If we know how to do it safely, disable the PHP engine entirely. <IfModule mod_php5.c> php_flag engine off </IfModule> </Directory> # Prevent direct reading of files in the private dir. # This is for Drupal7 compatibility, which would normally drop # a .htaccess in those directories, but we explicitly ignore those <Directory "/var/www/drupal/sites/example/private/" > <Files *> SetHandler This_is_a_Drupal_security_line_do_not_remove </Files> Deny from all Options None Options +FollowSymLinks # If we know how to do it safely, disable the PHP engine entirely. <IfModule mod_php5.c> php_flag engine off </IfModule> </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/drupal ServerName example SetEnv db_type mysql SetEnv db_name example SetEnv db_user example SetEnv db_passwd 1234567 SetEnv db_host somedb SetEnv db_port 1234 ServerAlias example ServerAlias www.example <IfModule mod_rewrite.c> # these rules work for everything except: # example -> www.example RewriteCond %{HTTP_HOST} ^example\$ [NC] RewriteRule (.*) www.example$1 [R=301,L] RewriteCond %{HTTPS} off RewriteRule (.*) %{HTTP_HOST}%{REQUEST_URI} </IfModule> # Extra configuration from modules: # Error handler for Drupal > 4.6.7 <Directory "/var/www/drupal/sites/example/files"> <Files *> SetHandler This_is_a_Drupal_security_line_do_not_remove </Files> Options None Options +FollowSymLinks # If we know how to do it safely, disable the PHP engine entirely. <IfModule mod_php5.c> php_flag engine off </IfModule> </Directory> # Prevent direct reading of files in the private dir. # This is for Drupal7 compatibility, which would normally drop # a .htaccess in those directories, but we explicitly ignore those <Directory "/var/www/drupal/sites/example/private/" > <Files *> SetHandler This_is_a_Drupal_security_line_do_not_remove </Files> Deny from all Options None Options +FollowSymLinks # If we know how to do it safely, disable the PHP engine entirely. <IfModule mod_php5.c> php_flag engine off </IfModule> </Directory> </VirtualHost>解决方案
OK now I get it with the content of your virtualhost.
This is not valid:
RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Actually you can't use %{HTTP_HOST} or %{REQUEST_URI} in the RewriteRule part
That's why it's redirecting you to a non-existent host, hence the connection refused error.
You should use this rule in the ssl virtualhost:
RewriteEngine on RewriteCond %{HTTP_HOST} ^example\$ [NC] RewriteRule (.*) www.example$1 [R=301,L]And this one in the non ssl one:
RewriteEngine on RewriteCond %{HTTPS} off RewriteRule (.*) www.example$1 [R=301,L]HTH
更多推荐
重定向所有https://www.example.com
发布评论