我需要你的帮助。我想测试是否在没有 www 的情况下输入了 URL
喜欢example.com
它应该转发到www.example.com
。
我需要你的帮助。我想测试是否在没有 www 的情况下输入了 URL
喜欢example.com
它应该转发到www.example.com
。
试试这个 mod_rewrite 规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/$0 [NC,L,R=301]
如果您正在使用nginx
,则将此行添加到nginx config
:
server {
listen 80;
server_name yourdomain.com;
rewrite ^/(.*) http://www.yourdomain.com/$1 permanent;
}