Summary of domain name 301 redirection methods in apache/nginx environment

Source: Internet
Author: User
Tags to domain

Previously, Zhang xiaosan also summarized the tutorial of domain name 301 redirection, but it was messy. This time, I re-arranged it, in a simple and efficient nginx and apache environment, we strive to Redirect 301 domain names without WWW to domain names with WWW.

There are three methods for 301 redirection of nginx domain name:

Native nginx later versions support:

Server {
Server_name 111cn.net;
Return 301 http://www.111cn.net $ request_uri;
}

Rewrite nginx general support:

Server {
Server_name 111cn.net;
Rewrite ^ (. *) http://www.111cn.net $1 permanent;
}

Judge the rewrite method:

If ($ host! = 'Www .111cn.net '){
Rewrite ^/(. *) $ http://www.111cn.net/#1 permanent;
}
Apache domain 301 Redirection. htaccess

Method 1:

Options + FollowSymLinks
RewriteEngine on
RewriteRule (. *) http://www.111cn.net/#1 [R = 301, L]

Method 2:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.