Redirect 如何配置Apache2将URL从www重定向到,而不使用www

Redirect 如何配置Apache2将URL从www重定向到,而不使用www,redirect,apache2,Redirect,Apache2,这是否是一个有效的重拨命令,用于将在URL中写入www前缀的用户重拨到没有www前缀的同一URL <VirtualHost _default_:443> ServerName example.org ServerAlias www.example.irg RedirectMatch 301 https://www.example.org https://example.org ServerName example.org Serv

这是否是一个有效的重拨命令,用于将在URL中写入www前缀的用户重拨到没有www前缀的同一URL

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

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

ServerName example.org
ServerAlias www.example.irg
重定向匹配301https://www.example.org https://example.org

谢谢

不,它无效,
重定向匹配
无法查看您的域,正则表达式仅在您的URL路径上工作

https://
domain.com
/MyURL路径

您可以使用以下规则:

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