【发布时间】:2014-02-20 08:59:38
【问题描述】:
所以在过去的几个小时里,我一直对我的 .htaccess 文件无法正常工作感到沮丧。
我有两个子目录:secure.mysite.ca 和 storage.mysite.ca,它们都需要进行 ssl 加密。当我将 https 放在 URL 前面(即 https://secure.mysite.ca/ 或 https://storage.mysite.ca/)时,这些站点可以工作,但是当我将 http 放在前面时,它会重定向到我的根网站(http://mysite.ca/)。当有人尝试访问未加密版本时,我想重定向到站点的 https 版本。
我还想将所有访问 http://mysite.ca/ 的流量重定向到 http://www.mysite.ca/(即前面的 www)
这个 .htaccess 文件一年多以前可以工作,但现在不行了。
这是我在根文件夹中找到的 htaccess 文件:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.ca$ [NC]
RewriteRule ^(.*)$ http://www.mysite.ca%{REQUEST_URI} [R=permanent,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} ^(secure|storage)\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
我做错了吗?我应该在子目录中放置一个 .htaccess 文件吗?
编辑:这是 secure.fixnode.ca、storage.fixnode.ca 和 www.fixnode.ca 的虚拟主机配置文件。请让我知道我做错了什么
storage.fixnode.ca.conf
<VirtualHost *:443>
DocumentRoot "/var/www/fixnode_website/content/Online Storage"
<Directory "/var/www/fixnode_website/content/Online Storage">
allow from all
Options +Indexes
</Directory>
SSLEngine on
ServerName storage.fixnode.ca
SSLCertificateFile /path/to/cert/storage.crt
SSLCertificateKeyFile /path/to/private key/private.key
</VirtualHost>
secure.fixnode.ca.conf
<VirtualHost *:443>
DocumentRoot "/var/www/fixnode_website/content/Secure Login"
<Directory "/var/www/fixnode_website/content/Secure Login">
allow from all
Options +FollowSymlinks
</Directory>
SSLEngine on
ServerName secure.fixnode.ca
SSLCertificateFile /path/to/cert/cert.crt
SSLCertificateKeyFile /path/to/cert/mykey.key
</VirtualHost>
最后是我的根域 www.fixnode.ca.conf 的虚拟主机
<VirtualHost *:80>
DocumentRoot /var/www/fixnode_website
<Directory "/var/www/fixnode_website">
allow from all
Options +Indexes
</Directory>
ServerAlias fixnode.ca
ServerName www.fixnode.ca
</VirtualHost>
【问题讨论】:
-
你是说上面的 htaccess 代码以前有效,现在无效?
-
是的。目前访问secure.fixnode.ca的用户只有在手动将https://放在URL前面时才会被重定向到正确的站点。否则,如果用户只是访问 secure.fixnode.ca 而没有在前面输入 https:// 那么该用户将被重定向到我的根站点(fixnode.ca)
-
除非您对系统进行更改,否则通常不会更改。它应该会继续工作。
-
我最近更新到 apache 2.4。我认为更新破坏了我的 .htaccess 文件
-
是的,您可能在某处覆盖了 httpd.conf 文件并破坏了虚拟主机。
标签: .htaccess mod-rewrite redirect https apache2