深圳市创一网科技有限公司 0755-29183221

帮助企业提升品牌附加值

品牌战略+品牌设计+品牌营销

临沧301重定向:LNMP下实现301重定向的办法

浏览量(218668) 时间:2020-09-11

LNMP下实现301重定向办法一:编辑伪静态.htaccess文件

RewriteEngine on
RewriteCond %{http_host} ^szcew.com [NC]
RewriteRule ^(.*)$ https://www.szcew.com/$1 [L,R=301]

这种方法没有写permanent,没有的话也能重定向,但属于302重定向!


LNMP下实现301重定向办法二:打开/usr/local/nginx/conf/vhost下相应的.conf文件,原代码如下:

server
{
listen 80;
server_name www.szcew.com szcew.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.szcew.com; include none.conf;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
} location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
} location ~ .*\.(js|css)?$
{
expires 12h;
} access_log off;
}

把这里server_name www.szcew.com szcew.com; 的szcew.com删除掉,然后在代码的最下面再加上一个server段:

server {
server_name vpsdx.com;
rewrite ^(.*) https://www.szcew.com$1 permanent;
}

最后得到的完整代码是:

server
{
listen 80;
server_name www.szcew.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.szcew.com; include none.conf;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
} location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
} location ~ .*\.(js|css)?$
{
expires 12h;
} access_log off;
}

server {
server_name szcew.com;
rewrite ^(.*) https://www.szcew.com$1 permanent;
}

LNMP下实现301重定向办法三:LNMP推荐的方法 ,这种方法效率高,


LNMP下的Nginx如果想将域名szcew.com 301重定向到www.szcew.com,同时www.szcew.com已经通过/root/vhost.sh添加上,可以按如下步骤修改,使用命令编辑器vi、nano或winscp图形管理软件编辑对应的虚拟主机,一般虚拟主机配置文件位于:/usr/local/nginx/conf/vhost/域名.conf ,如果添加的域名是www.vpsdx.com,则配置文件是/usr/local/nginx/conf/vhost/www.szcew.com.conf ,在配置文件最后面加上如下代码:

省略www.szcew.com虚拟主机server配置
server {
listen 80;
server_name szcew.com;
return 301 https://www.szcew.com$request_uri;
}

如果想将域名www.szcew.com 301重定向到szcew.com,同时szcew.com已经通过/root/vhost.sh添加上,则编辑对应的虚拟主机,一般虚拟主机配置文件位于:/usr/local/nginx/conf/vhost/szcew.com ,如果添加的域名是www.vpsdx.com,则配置文件是/usr/local/nginx/conf/vhost/www.szcew.com,在配置文件最后面加上如下代码:

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

得到的完整代码如下:

server
 {
 listen 80;
 #listen [::]:80;
 server_name szcew.com; //此处把www.szcew.com域名删除//
 index index.html index.htm index.php default.html default.htm default.php;
 root /home/wwwroot/szcew.com;

 include other.conf;
 #error_page 404 /404.html;

 # Deny access to PHP files in specific directory
 #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

 include enable-php.conf;

 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
 {
 expires 30d;
 }

 location ~ .*\.(js|css)?$
 {
 expires 12h;
 }

 location ~ /.well-known {
 allow all;
 }

 location ~ /\.
 {
 deny all;
 }

 access_log /home/wwwlogs/wget.ee.log;
 }
//下面为新增的代码 //
server {
listen 80;
server_name www.szcew.com;
return 301 http://szcew.com$request_uri;
}

添加完成后保存,执行:/etc/init.d/nginx restart 重启nginx,使其生效。

如果是想让http强制跳转到https,把里面的http换成https就行。
例:

server {
listen 443 ssl;
server_name www.szcew.com;
省略其他配置
}
server {
listen 80;
server_name www.szcew.com;
return 301 https://www.szcew.com$request_uri;
}

推荐文章
临沧阿里CMO董本洪开讲新商业变革的“无忌之谈”,从电商到新零售
临沧你要运营流量,更要运营超级用户-阿里CMO董本洪
临沧策略中心四大价值,三大功能
临沧策略中心 - 2+8 应用场景(下)
临沧策略中心 - 2+8 应用场景(上)
最新动态
临沧阿里CMO董本洪开讲新商业变革的“无忌之谈”,从电商到新零售
8月14日,阿里巴巴集团CMO、阿里妈妈事业部总裁董本洪(花名张无忌)出席在台湾举办的“新零售·新商业”公开课,解读新零售背景下的新商业模式和发展趋势,该活动由淘宝大学、阿里妈妈和台湾远见杂志合办,吸引了近700名台湾中小企业和创业者的热烈参与。
临沧你要运营流量,更要运营超级用户-阿里CMO董本洪
4月26日,阿里巴巴集团CMO、阿里妈妈总裁董本洪(花名:张无忌)在《天下网商》主办的2018新网商营销大会上,来一场“无忌之谈”。
临沧策略中心四大价值,三大功能
基于“统一身份识别”策略中心源于阿里全量数据,实时Real-time全量Sizable全维Dimensional,解决策略制定&应用痛点。
临沧策略中心 - 2+8 应用场景(下)
品牌挑战:1.Darphin作为雅诗兰黛旗下的小众品牌,已经有海淘C店进行代购,在淘内有一定的声量,但覆盖不大。2.为了惠及更多的中国消费者,品牌决定讲Darphin正式引入中国。
临沧策略中心 - 2+8 应用场景(上)
策略制定:品类发展策略,品牌发展策略,竞争策略,新品策略,按策略制定节奏推进。营销策划:品牌沟通,新品上市,消费者体验,消费者互动,按营销活动节奏推进。
临沧策略中心业务FAQ
阿里巴巴将全域生态中不同应用的消费者账号识别统一到自然人,及其在阿里生态内可识别的行为归因而形成的数据架构体系, 这一数据基础设施被称为 Uni ID Infrastructure,即“统一身份识别体系”。阿里巴巴的全域生态应用包括电子商务、娱乐(视频、新闻、电影、音乐等)、社交...
临沧什么是交叉链接?对SEO有什么作用?
交叉链接的基础还是友情链接,但是普通的友情链接是两个站之间交换链接,交叉链接三个站或者更多站交换。例如:我有两个站,一个是A站,一个是B站,而和我交换的人有一个C站,那么我想和你做交叉链接从而重点做A站的权重,那么将超链接就是B站链接你的C站,而C站不需要链接给B站,直接链接给A...
临沧经久不衰的SEO到底有多牛?
拥有20年历史的域名与维持2年的域名不具有可比性。不要误导所谓的旧域名。此处提到的旧域名是指已构建和更新的域名,请不要盲目。要购买域名,如果要购买,则必须购买可继续构建且正在更新网站的域名。此类网站通常已经过百度沙盒期。网站建立后,您可以在其中添加原始内容,并且几乎在第二天就包含...

做品牌直接找总监谈

总监一对一免费咨询与评估