Nginx no-www to www,www to no-www我在用Rackspace云上的Nginx教程搜索過網絡到目前為止還沒能解決這個問題。由于SEO和其他原因,我希望www.mysite.com在.htaccess中像往常一樣訪問mysite.com。我的/etc/nginx/sites-available/www.example.com.vhost配置:server {
listen 80;
server_name www.example.com example.com;
root /var/www/www.example.com/web;
if ($http_host != "www.example.com") {
rewrite ^ http://example.com$request_uri permanent;
}我也試過server {
listen 80;
server_name example.com;
root /var/www/www.example.com/web;
if ($http_host != "www.example.com") {
rewrite ^ http://example.com$request_uri permanent;
}我也試過了。第二次嘗試都會產生重定向循環錯誤。if ($host = 'www.example.com' ) {
rewrite ^ http://example.com$uri permanent;
}我的DNS作為標準設置:site.com 192.192.6.8 A type at 300 seconds
www.site.com 192.192.6.8 A type at 300 seconds(示例IP和文件夾已用于示例并在將來幫助人們)。我使用Ubuntu 11。
3 回答

侃侃無極
TA貢獻2051條經驗 獲得超10個贊
if ($host ~* ^www\.(.*)$) { rewrite / $scheme://$1 permanent; }
添加回答
舉報
0/150
提交
取消