问题
I need your help. I want to test if the URL is entered without www
like example.com
it should be forwarded to www.example.com
.
回答1:
Try this mod_rewrite rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
回答2:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com/$0 [NC,L,R=301]
回答3:
If you are using nginx
, then add this line to nginx config
:
server {
listen 80;
server_name yourdomain.com;
rewrite ^/(.*) http://www.yourdomain.com/$1 permanent;
}
来源:https://stackoverflow.com/questions/2272159/redirecting-url-without-www-to-www