网上查了一下linux 301重定向的代码,都是说要在 .htaccess 文件中添加重定向代码,但是我试了好多次,都没有成功。这是怎么回事?莫非这些代码都有错误?
于是,我又继续查找资料,最终在阿里云论坛里找到了答案,不看不知道,一看吓一跳哇,方法非常简单,不是在.htaccess 文件里修改,而是要在 .conf 文件里修改,就是你绑定域名的那个文件里修改,如果你用的阿里云自带的系统,那么这个.conf文件在 /alidata/server/nginx-1.2.5/conf/vhosts 这个目录里。打开这个文件phpwind.conf编辑:
server {
listen 80;
server_name www.xiaochunchun.com xiaochunchun.com;
if ($host != 'www.xiaochunchun.com' ) {
rewrite ^/(.*)$ http://www.xiaochunchun.com/$1 permanent;
}
index index.html index.htm index.php;
root /alidata/www/ycsc/web;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
include /alidata/server/nginx/conf/rewrite/phpwind.conf;
access_log /alidata/log/nginx/access/ycsc.log;
}
检验是否配置正确,连接远程控制
cd /alidata/server/nginx/sbin/
输入命令:
./nginx -t
出现如下两行,即表示配置正确。
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
重启nginx~ 输入指令(仍在在sbin目录下)~
./nginx -s reload
测试成功,利用站长之家检测:
http://tool.chinaz.com/pagestatus