301 redirect Code Analysis for Linux URLs _linux

Source: Internet
Author: User
Tags http redirect

So all use Linux host, I will define a 301 redirect to facilitate SEO. Yesterday, as usual htaccess uploaded to the server, did not expect to post the site can not be accessed, a delete will return to normal. Read a lot of code, also did not find any problems. Simply re-learn the URL rewrite method.
Normalize URLs
Describe:
On some Web servers, a resource can have more than one URL. Standard URLs should be used in actual applications and releases, others are abbreviated or used only internally. Whatever form of URL the user uses in the request, the final sight should be the canonical URL.
Solution:
Performs an external HTTP redirect on all irregular URLs to change its display in the browser's address bar and its subsequent requests. The rule set in the following example replaces the/~user with the canonical/u/user and corrects the suffix slash that/u/user omits.
Rewriterule ^/~ ([^/]+)/? (. *)/u/$1/$2 [R]
Rewriterule ^/([Uge])/([^/]+) $/$1/$2/[R]

Normalize host names

Describe:
The purpose of this rule is to force a specific host name to be used instead of another name. For example, if you want to force the use of www.example.com instead of example.com, you can modify it on the basis of the following scenarios:
Solution:
For sites that are running on ports other than 80

Rewritecond%{http_host}!^fully\.qualified\.domain\.name [NC]
Rewritecond%{http_host}!^$
Rewritecond%{server_port}!^80$
Rewriterule ^/(. *) http://fully.qualified.domain.name:%{server_port}/$1 [l,r]

For sites running on port 80

Rewritecond%{http_host}!^fully\.qualified\.domain\.name [NC]
Rewritecond%{http_host}!^$
Rewriterule ^/(. *) http://fully.qualified.domain.name/$1 [l,r]

Refer to the above rules, found that their original code missing a! Number, plus the return to normal.
Options +followsymlinks
Rewriteengine on
Rewritecond%{http_host}!^do-javascript.com [NC]
Rewritecond%{http_host}!^$
Rewriterule ^/(. *) http://www.do-javascript.com/$1 [R=301,NC]

Related Article

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.