您的位置:首页 > 运维架构 > Nginx

nginx和apache:配置301跳转(实现自动加www前缀)

2012-09-15 17:16 771 查看
nginx

例:
server {
listen       80 default;
server_name  www.test.com test.com;
location / {
root   /data/webroot/test;
index index.html;
if ($host !~* ^www) {
set $name_www www.$host;
rewrite ^(.*)$ http://$name_www$1 permanent;
}
}
}


apache

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/data/webroot/test"
ServerName test.com
ServerAlias www.test.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test.com  [NC]
RewriteRule ^(.*)$ http://www.test.com$1 [R=permanent,L]
</VirtualHost>


本文出自 “notepad” 博客,请务必保留此出处http://sndapk.blog.51cto.com/5385144/991851
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: