Home >Backend Development >PHP Tutorial >How to get the address bar url in php pseudo-static

How to get the address bar url in php pseudo-static

WBOY
WBOYOriginal
2016-07-25 09:13:161521browse

After the program became pseudo-static, search engines included a large number of previous dynamic addresses. How to deal with it? You may think that setting 301 is enough, but it seems that it will take quite a while for search engines to update 301, and it is still a bit difficult to access the previous dynamic address when searching. After all, you still want to access the static address, so you need to add it to the page. Make a judgment call.

First of all, I used the PHP built-in function. Because the program was pseudo-static, I found that the real URL addresses obtained were basically different from the displayed URL. I searched online for a long time and couldn't find a solution. The problem is indeed very difficult.

I accidentally saw an asp example, which contained: http_x_rewrite_url, so I tried it with php, but unexpectedly I could get the address in the address bar, and the problem was solved.

Example, how to get the address bar URL using PHP pseudo-static.

  1. if (strstr($_server["http_x_rewrite_url"], ".php") { //Determine whether the address of .php is included.
  2. header("http/1.1 301 moved permanently" );
  3. header("location: http://bbs.it-home.org/$id.html"); //Jump to the new static address.
  4. exit;
  5. }
  6. //Only applicable to windows. Server, liunx needs to use $_server['request_uri'] to obtain
  7. if (strstr($_server['request_uri'],".php") { //Determine whether the address of .php is included.
  8. header("http/ 1.1 301 moved permanently");
  9. header("location: http://bbs.it-home.org/$id.html"); //Jump to the new static address.
  10. exit;
  11. //Just enter The previous dynamic address will be transferred to the new static address in 301 manner
  12. ?>
Copy code
.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn