Universal 301 redirection method under IIS: pseudo-static URL rewriting + php301

Source: Internet
Author: User

 

Core tips: you usually have different 301 redirection requirements under different circumstances, if you want to transfer a domain name without WWW 301 to a domain name with WWW, the old domain name 301 will be idle to the primary domain name, the Forum 301 originally placed in the subdirectory to the new BBS second-level domain name, change the Domain Name redirects 301 of all pages under a domain name to the corresponding page under the new domain name.

As we all know, 301 redirection is the most useful jump method, which not only achieves Seo affinity jump, but also implements weight transfer.

We usually have different 301 redirection requirements under different circumstances, if you want to transfer a domain name without WWW 301 to a domain name with WWW, the old domain name 301 will be idle to the primary domain name, the Forum 301 originally placed in the subdirectory to the new BBS second-level domain name, change the Domain Name redirects 301 of all pages under a domain name to the corresponding page under the new domain name.

To analyze 301 of the requirements in different situations, we must ensure the following two points:

1) The jump is successful and the 301 status is correctly sent.

2) redirect the original page to the new page

The first point is how to implement a variety of 301 redirection tutorials. The second point is that different CMS/programs and different environments make it easy to have a unified solution. Next, let's take a brief look at how IIS (servers and virtual hosts) performs a correct 301 redirect, next, we will focus on the simple 301 jump Method-URL pseudo static rewrite + php301 jump, which is the best way to redirect all programs to the corresponding page.

1. correctly implement basic 301 redirection in IIS:

For example, if I want to permanently rewrite pmume.com 301 to www.pmume.com to ensure that the website domain name is single and the weight is concentrated, then:

1) server: If you have operation permissions on the server, directly create another website and set "permanent resource redirection" on IIS ":

2) Virtual Host: bind a domain name without WWW to a sub-directory in the background of the IDC virtual host, place an index. php under the sub-directory, and put the code of 301 redirection in it:

<? PHP
Header ("HTTP/1.1 301 moved permanently ");
Header ('location: http://www.pmume.com /');
Exit;
?>

The operations on IIS on the above server can not only jump to the homepage, but also jump to the corresponding page under the new domain name on all subpages under the original domain name by selecting "permanent resource redirection, the 301 jump code on the VM can only jump to the home page or a single directory.

2. Universal 301 for page Jump: URL pseudo-static rewriting + php301

There are many ways to jump to page 301. the most stupid way is to manually jump to a page 301 to the corresponding new page, but it is not operable, unless there are only a few pages, it is basically impossible to update 301 of domain names. So how can we achieve the 301 jump of the corresponding page in general? What is the URL pseudo-static + php301 operation?

To achieve the corresponding page Jump, first analyze the structure of the original page url, then analyze the URL rules of the new page, and then implement the jump of 301, fallen Leaves use the URL pseudo-static + php301 operation to analyze the original URL rules and use httpd in IIS. the pseudo-static function in ini overwrites the original URL regular expression to a single PHP entry, and obtains the feature string of the original URL through the single PHP, corresponding to the feature string to jump to the new page.

The above sentence has actually summarized the entire operation method. The following example shows the actual implementation.

Example 1: I want to replace the Forum www.abc.com/bbs/example In the subdirectory with bbs.abc.com.

A. pseudo static rewrite URL:

Place the following pseudo-static rules in the httpd. ini file under the root directory.

[Isapi_rewrite]
#3600 = 1 hour
Cacheclockrate 3600
Repeatlimit 32
# Protect httpd. ini and httpd. parse. Errors files
# From Accessing through HTTP
Rewriterule ^ (. *)/BBS/(. *) $1/BBS/301 \. php \? Go = $2 [l]

Purpose: rewrite all links in the BBS directory to index. php and use the go parameter for transmission. For example, rewrite the link at http://www.abc.com/bbs/thread-112-1.htmlto http://www.abc.com/bbs/301.php? Gow.thread-112-1.html, the next step in index.php received gow.(such as thread-112-1.html), 301 jump to the http://bbs.abc.com/thread-112-1.html. Convert multiple inner pages to a single entry through index. php for centralized control.

B. Receive parameters in 301. php and implement 301 permanent redirection:

<? PHP
$ Go = $ _ Get ['Go']; // get the link section of the jump page, such as "thread-112-1.html" and Forum. php? FID = 32, etc.
Header ("HTTP/1.1 301 moved permanently"); // sends the 301 status, and all subsequent redirects are 301
Header ('location: http://bbs.abc.com/'.w.go); // jump to the corresponding page according to the Go Parameter
Exit;
?>

Example 2: My original forum is placed under the main domain name www.abc.com. Now the main domain name wants to make a post site, and the forum will be changed to bbs.abc.com, I think some URLs of the original www.abc.com domain name in the original Forum are all 301 to the corresponding page of bbs.abc.com, but the content of the new article is not redirected.

For example, www.abc.com/forum-1-1.html

Www.abc.com/thread-1-1-1.html

Www.abc.com/tag-rjd6424aa.html

Jump to bbs.abc.com/forum-1-1.html

Www.abc.com/article/123.htmland so on.

A. Analyze the types and general formats of the URLs you want to redirect:

As you mentioned above, there are forum Forum article list pages, forum post content pages, and Forum tag tabs. The URL structure of these three types of pages is very typical, that is, what you said:

Www.abc.com/forum-1-1.html

Www.abc.com/thread-1-1-1.html

Www.abc.com/tag-rjd6424aa.html

B. rewrite all these feature pages to a 301. PHP page in pseudo-static mode:

Post list page: rewriterule ^ (. *)/Forum-(. *) $1/301 \. php \? Go = Forum-$2 [l]
Post content page: rewriterule ^ (. *)/thread-(. *) $1/301 \. php \? Go = thread-$2 [l]
Tag tab: rewriterule ^ (. *)/Tag-(. *) $1/301 \. php \? Go = tag-$2 [l]

Other feature pages are similar to rewriting, so you need to have some knowledge about pseudo-static regular expressions.

3. php301 jump:

<? PHP
$ Go = $ _ Get ['Go'];
Header ("HTTP/1.1 301 moved permanently ");
Header ('location: http://bbs.abc.com/'.w.go );
Exit;
?>

This original fallen leaf URL pseudo static rewrite + php301 method (HA, It is coincidental if there are similar), a hundred trial is not good, but the key point is that you need to understand the writing of pseudo static rules. This actually involves some knowledge about regular expressions, but I believe that you only need to take a closer look at the pseudo-static rules provided by your CMS or forum programs and observe them carefully, you can perform the 301 jump following the above example.

Author: fallen leaves (t.qq.com/guohui)

Website: http://www.pmume.com respect copyright, reprinted please indicate the source, the original first chinaz!

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.