在.htaccess中使用HTTPS将旧域重定向到新域

时间:2015-11-17 11:12:21

标签: apache .htaccess mod-rewrite redirect server

我们说我们有,
旧域:http://www.olddomain.com
新域:https://www.newdomain.org

这是我的.htaccess文件数据:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule ^/?$ "https\:\/\/www\.newdomain\.org\/" [R=301,L]

有时在重定向时,浏览器会显示安全错误,使其不受信任。

现在,

  1. 如何成功?
  2. 如何将其从非www重定向到www?

1 个答案:

答案 0 :(得分:2)

在测试之前更改规则的顺序并清除浏览器缓存:

/*
 * override "Today" button to also grab the time and set it to input field.
 */
$.datepicker._base_gotoToday = $.datepicker._gotoToday;
$.datepicker._gotoToday = function(id) {
    var inst = this._getInst($(id)[0]);
    this._base_gotoToday(id);
    var tp_inst = this._get(inst, 'timepicker');
    var tzoffset = $.timepicker.timezoneOffsetNumber(tp_inst.timezone);
    var now = new Date();
    var utcNow = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds());
    this._setTime(inst, utcNow);
    tp_inst._onSelectHandler();
};