Apache 301 redirects a domain name with www to a domain name without www

Source: Internet
Author: User
Tags to domain

I have never paid much attention to this blog jump problem. By accident, a friend said that my blog www.111cn.net and 111cn.net did not do 301. This is indeed the case. Although the main domain name 111cn.net is set in the blog background, when www.111cn.net is accessed, it does not jump. Therefore, the following code is added to. htaccess, which perfectly enables apache to redirect other domain names (such as domain names with www) to domain names without www and record them for sharing. The code is as follows:

Environment:

Windows
In Apache 2.2

The code to be implemented is as follows:

The code is as follows: Copy code

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

If mod_rewrite is not available, you can also set mod_alias:

The code is as follows: Copy code

RedirectMatch 301 ^ (. *) $ http://www.111cn.net

Reminder

Load the Rewrite module:

Find httpd. conf in the conf Directory

LoadModule rewrite_module modules/mod_rewrite.so

Remove the comment symbol "#" from the front or add this sentence.

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.