日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

LNMP下实现301重定向的三种办法

發布時間:2023/11/21 综合教程 30 生活家
生活随笔 收集整理的這篇文章主要介紹了 LNMP下实现301重定向的三种办法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LNMP下實現301重定向的辦法。
方法一:

編輯偽靜態.htaccess文件

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

這種方法沒有寫permanent,沒有的話也能重定向,但屬于302重定向!

方法二:

打開/usr/local/nginx/conf/vhost下相應的.conf文件,原代碼如下:

server
{
listen 80;
server_name www.fengjunzi.com fengjunzi.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.myhuabao.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.fengjunzi.com fengjunzi.com; 的fengjunzi.com刪除掉, 然后在代碼的最下面再加上一個server段:

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

最后得到的完整代碼是:

server
{
listen 80;
server_name www.fengjunzi.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.fengjunzi.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 fengjunzi.com;
rewrite ^(.*) https://www.fengjunzi.com$1 permanent;
}

方法三:

具體這種方法效率高,目前我們采用的此方法。 例如虛擬主機配置文件位于:/usr/local/nginx/conf/vhost/域名.conf ,如添加的域名是www.fengjunzi.com則配置文件是/usr/local/nginx/conf/vhost/www.fengjunzi.com.conf 在配置文件最后面加上如下代碼:

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

這樣用戶打開fengjunzi.com時候就會轉到www.fengjunzi.com去了,注意,fengjunzi.com雖然用了301重定向,但還是要做A記錄解析。

本文轉自:https://www.22vd.com/5239.html

總結

以上是生活随笔為你收集整理的LNMP下实现301重定向的三种办法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。