开发者

Redirect domain when there isn't a subdomain with htaccess

When someone types 开发者_如何学Pythonhttp://example.com I need it to be redirected to http://www.example.com but if someone goes to http://somenthing.example.com it should not be redirected.

I've been trying different rules with no luck, can anyone point to me the right htaccess rule to use here?


Try this

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


Use this rule (place it on the top of your .htaccess .. as order of rules matters):

RewriteEngine On

# force www
RewriteCond %{HTTP_HOST} =example.com [NC]
RewriteRule .* http://www.example.com%{REQUEST_URI} [L,R=301]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜