如何配置 Apache2 以将 URL 从 www 重定向到没有 www


这是一个

有效的 redict 命令,用于将 URL 中将 www 前缀写入同一 URL 的用户重新定义,而无需 www。

<VirtualHost _default_:443>
        ServerName example.org
        ServerAlias www.example.irg
        RedirectMatch 301 https://www.example.org https://example.org

谢谢

不,它无效,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

最新更新