开发者社区> 问答> 正文

访问不带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的修改,但是没什么效果:

        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;
        }
    }

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

来源:思否

展开
收起
刘刚_ 2020-05-13 17:24:12 1203 0
1 条回答
写回答
取消 提交回答
  • 努力努力再努力

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

    来源:思否

    2020-05-13 17:25:12
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
创新改变行业——释放域名生态的力量 立即下载
“域”见更美好的未来——域名筑梦互联网+ 立即下载
“域”感——《域名投资从入门到精通》 立即下载