Linux URL 301 redirection code analysis

Source: Internet
Author: User

Therefore, I will define a 301 redirection for any Linux host to facilitate Seo. I uploaded htaccess to the server as shown in the following example yesterday. I did not expect the website to be inaccessible after it was uploaded, And it will return to normal after it is deleted. I read it many timesCodeAnd no problems were found. Simply re-learn the URL rewriting method.
Normalized URL
Description:
On some Web servers, a resource has multiple URLs. Standard URLs should be used in actual applications and releases, while others should be abbreviated or used only internally. No matter what form of URL the user uses in the request, the final view should be a standard URL.
Solution:
Execute an external HTTP redirection for all non-standard URLs to change the display in the browser address bar and its subsequent requests. In the following example, replace the rule set with the standard/u/user /~ And corrected the suffix slash that/u/user missed.
Rewriterule ^ /~ ([^/] + )/? (. *)/U/$1/$2 [R]
Rewriterule ^/([uge])/([^/] +) $/$1/$2/[R]

Canonicalized Host Name

Description:
The purpose of this rule is to force a specific host name to replace other names. For example, if you want to force www.example.com to replace example.com, you can modify it based on the following solution:
Solution:
For Sites running on non-port 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]

After referring to the above rules, I found that my original code was missing! .
Options + followsymlinks
Rewriteengine on
Rewritecond % {http_host }! ^ Do-javascript.com [Nc]
Rewritecond % {http_host }! ^ $
Rewriterule ^/(. *) http://www.do-javascript.com/#1 [R = 301, 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.