找回密碼
 立即註冊
搜索
熱搜: 活動 交友 discuz
查看: 478|回復: 0

新增或移除 www 前置 301

[複製鏈接]

257

主題

38

回帖

1138

積分

管理員

積分
1138
發表於 2023-5-25 09:03:34 | 顯示全部樓層 |閱讀模式

Add WWW PREFIX IN DOMAIN URL

Go to your website’s home directoty:

cd /home/username/public_html

Open the .htacess file with any of your favourite editors:

nano .htaccess

Insert the following code in file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domainname.com
RewriteRule (.*) http://www.domainname.com/$1 [R=301,L]

Save the file.

Assign proper ownership to the file.

This will redirect all requests to the non-www version of your site to the www version using 301.

 

For Nginx users add the following code in domains server block.

server {
 server_name example.com;
 return 301 http://www.example.com$request_uri;
}

Remove WWW Prefix in Domain URL

Add the following code in your web server configuration. This will remove www prefix from site url. If some one opened site with www, this will redirect to non-www url.

Apache users add the following code in your website .htaccess file. It will required the mod_rewrite enabled on your server, without mod_rewrite it will not work.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Nginx users add the following code in domains server block.

server {
 server_name www.example.com;
 return 301 http://example.com$request_uri;
}
您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|小黑屋|DoIT 科技論壇

GMT+8, 2025-6-16 04:40 , Processed in 0.012337 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表