Open PHP Pseudo-static mode _php instance

Source: Internet
Author: User
Tags session id

have been doing PHP development work. In the process of development has long heard the "pseudo static" this said. But there has been no understanding of it. Today through this article carefully study.

First, what is pseudo static:

Pseudo static also name URL rewrite that is dynamic URLs that look like static URLs. In other words, dynamic Web pages are implemented by rewriting the URL method to remove the parameters of the Dynamic Web page, but there is no need to implement an overridden page in the actual page directory.

1. Detect if Apache supports Mod_rewrite

View the environment configuration through the Phpinfo () function provided by PHP, and find the "Loaded Modules" through ctrl+f, which lists all
Apache2handler already open modules, if the inside includes "Mod_rewrite", then already supported, no longer need to continue setting.

If "Mod_rewrite" is not turned on, open the directory under your Apache installation directory "/apache/conf/" under the httpd.conf text
Pieces, find the "LoadModule rewrite_module" through ctrl+f, and remove the "#" number in front of it.

If it is not found, go to the LoadModule area, add "LoadModule rewrite_module modules/mod_rewrite.so" (the required exclusive line) on the last line, and then restart the Apache server.

2. Configure the virtual host in httpd.conf

# Virtual hosts enable hosting
Include conf/extra/httpd-vhosts.conf

3.httpd_vhosts.conf file, configure the appropriate options. Detailed explanation

<virtualhost *:80>
  documentroot "c:/myenv/apache/htdocs/static3"
  ServerName www.hsp.com
  < Directory "C:/MYENV/APACHE/HTDOCS/STATIC3" >
#Deny from the all 403 error prompts
Allow
from the all #如果文件目录在apache目录外面, Comment out Optinos, not list.
The options +indexes
#下面这个表示可以去读取. htaccess file, or you can configure it directly in the virtual host.
AllowOverride all
rewriteengine on
rewriterule News-id (\d+). html$ error.php?id=$1
#这里可以设置多个重写的规则
#RewriteRule news-id.html$ error.php
  </Directory>
 </VirtualHost>

4. Write in the appropriate directory. Htaccess rewrite rules

Example:

<ifmodule rewrite_module>
rewriteengine on
rewriterule News-id (\d+). html$ show.php?id=$1
Here you can set up multiple overridden rules
#RewriteRule news-id.html$ error.php
</IfModule>

If you can create it directly under Linux,

If you are in a Windows platform, create a file with Notepad, such as Abc.txt, and Save as a. htaccess file

5. Rewrite the rules, or configure the <Directory> section of the virtual host directly.

Advantages and disadvantages of dynamic, static and pseudo-static (new)

Dynamic Web site

First of all, Dynamic Web site currently for Google, "can not be crawled" is wrong, Google can handle dynamic web site and smooth crawl, followed by "No more than 3" argument is not correct, Google can crawl parameters of more than 3 dynamic URLs, however, To avoid the URL being too long, you should minimize the parameters.

Second, Dynamic Web site has its certain advantages, to the above mentioned news.php? Lang=cn&class=1&id=2 as an example, the URL of the parameters of the accurate tell Google, the content language of the URLs for the CN, the subordinate belongs to Category 1, Content ID of 2, more convenient for Google to identify the content processing.

Finally, dynamic URLs should be as concise as possible, especially with the session identification (SID) and query parameters, which can easily result in a large number of identical pages.

Static URL

First of all, static Web sites have the absolute advantage of its clarity,/product/nokia/n95.html and/about.html can easily be understood, so that in search results may be relatively high clicks.

Second, static web site is not necessarily the best form of the Web site, the Dynamic Web site said, Dynamic Web site can tell Google some of the parameters can be identified, and static URLs if the document layout is not appropriate (such as: too flat, HTML documents are all placed in the root directory) and other factors, Rather than static web sites for Google to provide rich reference information.

Finally, do you think that Google has hidden meaning in this article? "Updating pages of this type of Web site can be time-consuming, especially if the amount of information grows fast, because each individual page must change the compiled code." "Although the site is said to be, is there such a problem in the Google system?"

Pseudo static URL

First of all, pseudo static URL can not let Dynamic Web site "static", pseudo static is just a dynamic URL of a rewrite, Google does not think pseudo static is HTML documents.

Secondly, pseudo static is desirable, but the focus should be placed on removing redundant parameters, specification URLs, and avoiding duplicate pages as much as possible.

Finally, pseudo static has great potential danger, preferably in the Web site system, site structure, content distribution, parameter meaning familiar with the use of the situation.

When writing pseudo static rules, you should keep valuable parameters, not all of the valuable parameters, such as the news.php in the previous example? Lang=cn&class=1&id=2 is best rewritten as a news-cn-class1-id2.html rather than an excessive simplification rewrite for news-2.html.

And then pseudo static must not contain the session identification (SID) and query (queries) parameters,/product.asp? sid=98971298178906&id=1234 such a dynamic URL, where the SID could have been identified and blocked by Google, but if rewritten as/product/98971298178906/1234,google not only unrecognized, It also creates an infinite number of duplicate pages throughout the station (each session will produce a new session ID).

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.