PHP implementation of 301 REDIRECT Code
PHP implements the 301 redirect code as follows:
Header (' http/1.1 301 Moved permanently ');//301 head issued
Header (' location:http://www. ') $strDomain. $request _uri);//jump to my new
This article explains how to set 301 redirection on IIS, APACHE, ASP, and PHP servers or page programs.301 redirection: it refers to a very important "automatic redirection" technology-in fact, it is not a technology, that is, URL redirection-the user can access an address or directory and specify to jump to another address.301 Redirection. This is the
PHP Implementation 301 Permanent Redirect the domain name without www to the domain name with www, that is, baidu.com redirect to Www.baidu.comIf you only need to complete this function, the PHP code can be written like this:1PHP2 $the _host=$_server[' Http_host '];//get access to the domain name you entered3 $request _url=isset($_server[' Request_uri '])?$_serve
the program, as above is constructed in the context of the request, If you want to test in the context of a program in the With App.test_request_context (): code blockJump Orientation:
Description: Flask.url_for is responsible for constructing the URL, while the flask.redirect is responsible for redirecting, receiving 2 parameters, the first is the URL address, the second parameter is the code status code, jump (301) for the old URL before disc
Web page changes to the search engine friendly after the best way to do is to do 301 redirect, if not temporarily to some or some of the Web page transfer, we all think to do 301 redirect more appropriate.
Web page changes to the search engine friendly after the best way to do is to do
The author's SEO blog does not use 301 redirect, mainly the virtual host does not support, or not. The 5 recommendations that preceded the standardization of URLs were mentioned slightly, but a situation was overlooked.
Under normal circumstances, we see in the search results page are omitted the default homepage, the main construction station program language has asp/php/jsp/.net, its default home page is
1. redirect Www.111cn.net to Www.111cn.net
Open the. htaccess file and add the following rules.
The code is as follows
Copy Code
Rewriteengine onRewritecond%{http_host}!^www.111cn.net$ [NC]Rewriterule ^ (. *) $ http://www.111cn.net/$1 [l,r=301]
2. redirect old.com to Www.111cn.net
The code is as follows
Cop
the Redirect is mainly to the domain name a jump to domain B, more often than not with the domain name of the WWW jump to the domain name with www, then 301 redirect how to do it, this article detailed introduction of the 301 redirect practice, the following is divided into
Some friends may use the method of comparing benzene, add Response.redirectpermanent method under each Controller. The simpler approach is to add the following code to the Global.axax.cs:
The code is as follows
Copy Code
protected void Application_BeginRequest (object sender, EventArgs e){String strurl = Request.Url.ToString (). Trim (). ToLower ();if (Strurl.contains ("Http://111cn.net")){Response.redirectpermanent ("Http://www.111cn.net"); Not good}}
If y
Popular Science:
301 permanent redirect: when a user or search engine sends a browser request to the website server, one of the status codes in the header information returned by the server in the HTTP data stream indicates that the webpage is permanently transferred to another address.
302 temporary jump is also a status code, meaning that it is temporarily redirected to another URL.
The main difference
Because of the need for revision, a section of the fire net needs to do 301 redirects, this is a long time ago the fire under the navigation of a search, using the ASP language, but spiders like, so can not delete, had to write a 301 redirect, but the original many URLs are parameters, such as tag tag, Form such as: Liehuo_tag.asp?q=%c1%d2%bb%f0%cd%f8.
Studied a
The web site from the Sina SAE moved over, the former domain name can also be accessed, so there will be two duplicate sites, not conducive to seo/seo.html "target=" "_blank" > Search engine included, and the previous weight will not be, so do a good link 301 Redirect, Open the Config.yaml file on the SAE:
Handle
The code is as follows
-Rewrite:if (in_header["host"] ~ "^101ban
The nginx301 jump setting is simple and is configured as follows. (The configuration file defaults to nginx.conf, if a new configuration file is developed, the new file configuration is available.)server{server_name xxx.com www.xxx.com;Rewrite ^/(. *) http://www.hablue.com/$1 permanent;}server{server_name xxx.com www.xxx.com;if ($host! = ' www.hablue.com ') {Rewrite ^/(. *) $ http://www.hablue.com/$1 permanent;}}Both of these scenarios can be implemented, remember not to and virtual host configu
Https force redirect without www 301
Many browsers are gradually updated to websites that only support https. Therefore, many http websites need to add https support. In this case, the jump between www and without www is required, because www and without www use different certificates, 301 redirection is required. The solution is as follows:
Here, we use www.bk
From: http://www.bnxb.com/host/win/200811/21-654.htmlGenerally, in IIS, the "redirect to URL" function takes effect only on the home page. 301 of the inner page is redirected to the home page.After checking the data, we found that parameters still need to be added to the 301 redirection.
Reference content is as follows:
$ S transmits the suffix of the requested
For example, when I want to access www. domainA. com1.js, I will automatically redirect 301 to www. domainB. com2.js. How to do it? For example, when I want www.domainA.com/1.js to be accessed, I will automatically redirect 301 to www.domainb.com/2.js. How to do it?
Reply content:
For example, when I want www.domainA
301 Redirect is not unfamiliar, sometimes there is a need to redirect a directory whole to a level two domain name, or the top-level domain request without WWW is all redirected to the two-level domain name with www. If it is Apache, it needs to be configured. Htaccess,nginx is not supported and needs to be implemented using rewrite directives in the configuratio
of the PHP page to enter the following code can be. The code is as follows:
Header ("http/1.1 moved Permanently");Header ("Location:http://www.111cn.net");?>
Second, for the Total station page 301 Jump Solution1, the establishment of 301.php files
(File name yourself)
? php
$the _host = $_server[' http_host '];//get the current domain name
$the _url = isset ($_server[' Reques
seo:301 redirection
For example, a Web page that has two URLs (for example, Www.x.com/you_10_1 and www.x.com/you_10) points to it.
Now you need to redirect Www.x.com/you_10_1 using 301 to Www.x.com/you_10, how do I do that?
------Solution--------------------
The framework has its own rewrite, the direct write will have the conflict, need you to write before
#强制重定向到wwwRewriteengine onRewritecond%{http_host} ^jb51.net/[NC]Rewriterule ^ (. *) $ http://www.jb51.net/$1 [l,r=301]#强制重定向到不带www的顶级域名Rewriteengine onRewritecond%{http_host}!^jb51.net/$ [NC]Rewriterule ^ (. *) $ http://jb51.net/$1 [l,r=301]Apache will redirect without www domain 301 to a domain name with www configura
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.