如何配置 Apache2 将 URL 从 www 重定向到没有 www
How to config Apache2 to redirect URL from www to without the www
这是否是一个有效的重定向命令,用于将在 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
这是否是一个有效的重定向命令,用于将在 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