htaccess不明白^ www \。规则,如果参数附加到网址

时间:2017-06-07 09:12:53

标签: apache .htaccess

.htaccess无法理解^www\.规则

#do not use this, because i want to redirect from https://www.somedomain.com
#RewriteCond %{HTTPS} off 

RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} ^somedomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.somedomain\.com$
RewriteRule ^/?$ "https\:\/\/somedomain\.com" [L,R=301]
#[NE,L,R=301] - NE|noescape

这给出了以下重定向,但速度很慢:

somedomain.com - > https://somedomain.com

www.somedomain.com - > https://www.somedomain.com

somedomain.com/folder/file - > https://somedomain.com/folder/file

www.somedomain.com/folder/file - > http://www.somedomain.com/folder/file

最后一个网址www.somedomain.com/folder/file未重定向到https。为什么?

2 个答案:

答案 0 :(得分:0)

您有$(document).on('ready', function() { $("#input-8").fileinput({ rtl: true, language: "he", allowedFileExtensions: [<?PHP echo VALID_IMG_FILES2 ?>], maxFileCount: <?PHP echo MAX_UPLOAD_FILES ?>, maxFilePreviewSize: 5120, // 5 MB maxImageWidth: 150, maxImageHeight: 100, resizePreference: 'height', resizeImage: true, theme: "explorer", validateInitialCount: true, // uploadUrl: "/file-upload-batch/2", showRemove: false, showUpload: false, required: true, overwriteInitial: false, initialPreviewAsData: true, layoutTemplates: { main1: "{preview}\n" + "<div class=\'input-group {class}\'>\n" + " <div class=\'input-group-btn\'>\n" + " {browse}\n" + " {upload}\n" + " {remove}\n" + " </div>\n" + " {caption}\n" + "</div>" } }); }); 的附加条件可能导致重定向过多。使用以下方法修复它:

   class ForegroundCheckTask extends AsyncTask<Context, Void, Boolean> {

  @Override
  protected Boolean doInBackground(Context... params) {
    final Context context = params[0].getApplicationContext();
    return isAppOnForeground(context);
  }

  private boolean isAppOnForeground(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
      return false;
    }
    final String packageName = context.getPackageName();
    for (RunningAppProcessInfo appProcess : appProcesses) {
      if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) {
        return true;
      }
    }
    return false;
  }
}

在测试之前完全清除浏览器缓存。

答案 1 :(得分:0)

这适用于所有带参数且无需的URL。 确实,在几个不同的浏览器中清除缓存并尝试多次重新登录页面非常重要。否则,可能会适用一些旧规则。

<%= image_tag @item.image_url %>

结果是:

somedomain.com - &gt; https://somedomain.com

www.somedomain.com - &gt; https://www.somedomain.com

somedomain.com/folder/file - &gt; https://somedomain.com/folder/file

www.somedomain.com/folder/file - &gt; https://www.somedomain.com/folder/file

让事情变得更快:

RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^somedomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.somedomain\.com$ [NC]
RewriteRule ^(.*)$ https://somedomain.com%{REQUEST_URI} [L,NE,R=301]

我相信如果有更多规则,你不应该放DirectoryIndex /index.php RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^typejoy\.biz$ #RewriteCond %{HTTP_HOST} ^typejoy\.biz$ [OR] #RewriteCond %{HTTP_HOST} ^www\.typejoy\.biz$ [NC] RewriteRule ^(.*)$ https://typejoy.biz%{REQUEST_URI} [L,NE,R=301] RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www\.typejoy\.biz$ [NC] RewriteRule ^(.*)$ https://typejoy.biz%{REQUEST_URI} [L,NE,R=301] RewriteCond %{HTTP_HOST} ^www\.typejoy\.biz$ [NC] RewriteRule ^(.*)$ https://typejoy.biz%{REQUEST_URI} [L, NE,R=301]