首页 \ 问答 \ 如何使用htaccess将www和非www重定向到特定域的https(how to redirect www and non www to https for specific domain using htaccess)

如何使用htaccess将www和非www重定向到特定域的https(how to redirect www and non www to https for specific domain using htaccess)

我需要将www和非www重定向到https。 我已经在stackoverflow上到处寻找,但找不到我正在寻找的东西。

规则是:

  • example.com和www.example.com以及https://example.com必须重定向到https://www.example.com
  • 必须与域和扩展example.com匹配。 它不能是一张外卡,它也匹配abc.com或123.com或example.net或其他任何东西
  • 必须仅匹配www子域。 它不能是与sub.example.com或thisisademo.example.com匹配的外卡

我目前有:

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

但是,如果有人进入www.example.com,它仍会转到http版本而不是https。

我认为我真正需要的是RewriteCond正则表达式以完全匹配,只有“example.com”和“www.example.com”

谢谢


I need to redirect www and non www to https. I have looked everywhere on stackoverflow but can't find quite what I'm looking for.

The rules are:

  • example.com and www.example.com and https://example.com must redirect to https://www.example.com
  • It must match the domain and extension example.com. It cannot be a wild card which also matches abc.com or 123.com or example.net or anything else
  • It must match for www subdomains only. It cannot be a wild card which also matches sub.example.com or thisisademo.example.com

I currently have:

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

However if someone enters www.example.com it still goes to the http version instead of https.

What I think I actually need here is RewriteCond regex to match exactly and only "example.com" and "www.example.com"

Thanks


原文:https://stackoverflow.com/questions/37109618
更新时间:2022-03-18 06:03

最满意答案

添加这个依赖

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
</dependency>

add this dependecy

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
</dependency>

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)