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>
转载于:https://blog.51cto.com/sndapk/991851