【发布时间】:2016-03-11 06:36:07
【问题描述】:
我正在尝试使用以下规则创建一个 .htaccess 文件:
http://www.example.com/test => https://example.com/test
http://test.example.com/test => https://test.example.com/test
https://www.example.com/test => https://example.com/test
这是我当前的 .htaccess 文件:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
但是这会导致一些奇怪的行为:
http://www.nebla.co.uk/ => https://nebla.co.uk/public_html
它还会导致子域上的重定向循环。
【问题讨论】:
-
在
RewriteRule前面加上RewriteCond HTTPS off怎么样?允许重定向的配置是什么? (目标部分带有public_html的那个?您是否尝试阅读文档?例如httpd.apache.org/docs/2.4/mod/mod_rewrite.html -
我确实已经阅读了文档并寻求帮助,但是似乎每个人都希望主站点转到 https 而所有子域都转到 http,我不希望这种行为。我已经更新了我的问题。
-
这些规则中没有
public_html。任何可能在“主”配置文件中定义的东西(通常httpd.conf,可能在/etc/httpd或*nix 服务器的'/etc/apache2` 中,不确定它们在哪里用于其他操作系统。(哦,和顺便说一句,我在测试时没有重定向到public_html) -
不幸的是,我无法访问任何配置文件,因为我正在使用托管服务,我想这会使问题更加“为什么要添加 public_html””
标签: apache .htaccess http https