【问题标题】:How to config Apache2 to redirect URL from www to without the www如何配置 Apache2 将 URL 从 www 重定向到没有 www
【发布时间】:2018-04-20 01:41:51
【问题描述】:

这是一个有效的redict命令,用于将在URL中写入www前缀的用户重定向到没有www的相同URL。

<VirtualHost _default_:443>
        ServerName example.org
        ServerAlias www.example.irg

        RedirectMatch 301 https://www.example.org https://example.org

谢谢

【问题讨论】:

    标签: redirect apache2


    【解决方案1】:

    不,它无效,RedirectMatch 看不到您的域,正则表达式仅适用于您的 URL 路径。

    https://domain.com/my-URL-path

    你可以使用这些规则:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !=""
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    

    https://www.example.org/home 的查询将被重定向到https://example.org/home

    【讨论】:

      猜你喜欢
      • 2022-09-27
      • 2020-02-02
      • 2019-10-26
      • 2021-09-13
      • 1970-01-01
      • 2011-06-24
      • 2019-03-09
      • 2011-11-05
      • 2013-12-20
      相关资源
      最近更新 更多