代码之家  ›  专栏  ›  技术社区  ›  joshmoto

修改的最佳方法。htaccess ssl重定向以处理www,无子域

  •  1
  • joshmoto  · 技术社区  · 6 年前

    有什么方法可以修改这个工作吗 .htaccess 使用一些聪明的regex来处理多个子域的重定向。

    理想情况下,我希望能够使用 joshmoto.wtf 没有的域 www 在前面。

    能通电吗 .h访问 功能如下?

    如果你来…

    1. http://www.joshmoto.wtf 它重定向到 https://www.joshmoto.wtf
    2. http://joshmoto.wtf 它重定向到 https://joshmoto.wtf

    见以下电流 .h访问 它总是重定向 网址:http://joshmoto.wtf 网址:https://www.joshmoto.wtf

    <IfModule mod_rewrite.c>
        # Force SSL access
        RewriteEngine On
        RewriteBase /
    
        RewriteCond %{HTTP_HOST} !^www\.joshmoto\.wtf [NC]
        RewriteRule ^/?(.*) https://www.joshmoto.wtf/$1 [L,R,NE]
    </IfModule>
    

    任何专家regex的帮助将非常感谢。

    非常感谢

    1 回复  |  直到 6 年前
        1
  •  1
  •   wp78de    6 年前

    尝试如下:

    RewriteEngine On
    RewriteBase /
    # Redirect HTTP with www to HTTPS without www
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\.joshmoto\.wtf$ [NC]
    RewriteRule .* https://joshmoto.wtf%{REQUEST_URI} [R=301,L]
    # Redirect HTTP without www to HTTPS without www
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    # Redirect HTTPS with www to HTTPS without www
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^www\.joshmoto\.wtf$ [NC]
    RewriteRule .* https://joshmoto.wtf%{REQUEST_URI} [R=301,L]