doushengyou2617 2011-01-18 16:04
浏览 56

Apache http / https非www到ww url重定向

I've got a problem with apache configuration (linux distro). I want to redirect typed URLs (in browser):

domain.com
www.domain.com
http://domain.com
http://www.domain.com
https://domain.com

to only one: https://www.domain.com What should I do in .htaccess file? Notice that I've got only one certificate. Exactly for www.domain.com

Thank you in advance for any help! :)

  • 写回答

2条回答 默认 最新

  • dongteng2534 2011-01-18 16:09
    关注

    This rule should do it:

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTP_HOST} (.+) [OR]
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)
    RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]
    

    The four conditions are two groups of disjunct conditions where the first condition of each group tests for a missing www. and the non-HTTPS respectively. Each second condition of the groups are just to get the part of the HTTP host without the leading www..

    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入