访问不带www的域名直接下载文件,带www的可以访问

问题描述

访问不带www的域名直接下载文件,带www的可以访问
带www
不带www

问题出现的环境背景及自己尝试过哪些方法

阿里云服务器原来给别人用过一阵子,最近拿回来了重新初始化了。
然后这个域名原来是绑定在我用宝塔搭建的wordpress博客上的,初始化以后呢所有东西都清理了。但是访问不带www的域名会直接下载一个文件,文件内容如下:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

按照思否上提供的301重定向方法做了一下nginx.conf的修改,但是没什么效果:

server {
        listen 80;
        server_name rocwong.cn;
        return 301 http://www.rocwong.cn$request_uri;
    }

    server {
        listen       80;
        server_name www.rocwong.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
    }

补一张域名解析的配置信息图:
图片描述
希望各位大佬不辞吝教,提供一些解决方案和思路给我,谢谢啦~

阅读 6.8k
1 个回答
✓ 已被采纳新手上路,请多包涵

啊 本地缓存问题,换个电脑访问就可以了,301已经生效了。棒呆,给自己点个赞!

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏