Example of 301 redirection configuration for multiple domain names in apache

Source: Internet
Author: User
Tags to domain

One customer and two domain names must be accessible, so they must be resolved to the virtual host. This is not good for SEO. How can this problem be solved? Perform 301 redirection!
In the past, 301 redirection rules were applied to other customers, that is, the access to domain names without wwww automatically jumps to domain names with www, for example, access to abc.com automatically jumps to www.abc.com!
301
If you have a server, it is convenient to set permanent redirection directly in IIS. If not, what about virtual hosts? The VM needs to support isapi rewrite. My server has already installed the isapi rewrite function, so you can add rules directly in Httpd. ini.
There are other methods for Linux server. isapi rewrite seems to only support Windows server, so Httpd is used. ini rules, so if it is normal to do a 301 jump to a domain name, then use the following rule code.

A single domain name performs 301 redirection and redirects to. COM with WWW. Domain name.

The code is as follows: Copy code

RewriteEngine On
RewriteCond % {HTTPS} (on )?
RewriteCond % {HTTP: Host} ^ (?! Www.) (. +) $ [NC]
RewriteCond % {REQUEST_URI} (. +)
RewriteRule .? Http (? % 1 s): // www. % 2% 3 [R = 301, L]

But the user has two domain names. What should I do? If the VM supports Httpd. ini. Modify the following rules.

The two domain names perform 301 redirection and jump to the domain name with WWW. Domain name. COM.

The code is as follows: Copy code

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

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.