PHP pseudo-static mode open

Source: Internet
Author: User
Tags web hosting
In the previous article we introduced to you what is the PHP pseudo-static, and PHP use pseudo-static role, I believe many small partners to PHP pseudo-static have a certain understanding. So today we're going to show you how to start a static mode in PHP!

1. Detect if Apache supports Mod_rewrite

The Phpinfo () function provided by PHP looks at the environment configuration and finds "Loaded Modules" through ctrl+f, which lists all
Apache2handler already open module, if include "mod_rewrite", then already support, no longer need to continue to set.

If "Mod_rewrite" is not turned on, open the directory under your Apache installation directory "/apache/conf/" httpd.conf
To "LoadModule Rewrite_module" by ctrl+f, remove the "#" number from the front.

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

2. Configuring the virtual Host in httpd.conf

# Virtual hosts enable web 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 prompt from all# if the file directory is outside the Apache directory, comment out Optinos, Cannot list. Options +indexes# This indicates that you can read the. htaccess file, or you can configure it directly in the virtual host. allowoverride allrewriteengine onrewriterule News-id (\d+). html$ error.php?id=$1# Here you can set multiple overriding rules #rewriterule news-id.html$ error.php  </Directory> </VirtualHost>

4. Write in the appropriate directory. Htaccess rewrite rules

Example:

<ifmodule rewrite_module>rewriteengine onrewriterule News-id (\d+). html$ show.php?id=$1# Here you can set multiple overriding rules # Rewriterule news-id.html$ error.php</ifmodule>

If you can create it directly under Linux,

If you are under the Windows platform, create a file with Notepad, such as Abc.txt, and then save as a. htaccess file.

5. Rewrite the rules, or you can configure the <Directory> segment of the virtual host directly.

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

Dynamic URLs

First of all, the dynamic URL for Google, "can not be crawled" is wrong, Google can handle dynamic URLs and smooth crawl, followed by "parameters can not exceed 3" is not correct, Google can crawl parameters more than 3 dynamic URLs, however, To avoid URLs that are too long, you should minimize the parameters.

Secondly, the dynamic URL has its certain advantages, to the above mentioned news.php? lang=cn&class=1&id=2, for example, the URL of the parameters accurately tell Google, this URL content language is CN, is classified as Category 1, Content ID 2, more convenient for Google to identify the content processing.

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

Static URLs

First of all, the absolute advantage of static URLs is its clarity,/product/nokia/n95.html and/about.html can be easily understood, resulting in a relatively high number of hits in search results.

Second, the static URL is not necessarily the best form of the Web site, the dynamic URL said that dynamic URLs can tell Google some of the parameters can be identified, and static URLs if the document is not properly arranged (such as: too flat, the HTML document is placed in the root directory) and other factors, Rather than static URLs for Google to provide a rich reference information.

Finally, does it feel like Google has a hidden meaning in this article? "Updating pages of this type of URLs can be time-consuming, especially if the amount of information is growing fast because each individual page has to change the compiled code." "It's a website, but is there such a problem in Google's system?" he said.

Pseudo static URLs

First, pseudo-static URLs can not make dynamic URLs "static", pseudo-static is only a rewrite of dynamic URLs, Google does not think pseudo-static is an HTML document.

Second, pseudo-static preferable, but should focus on the removal of redundant parameters, canonical URLs, as far as possible to avoid repeating the page.

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

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

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

Summarize:

The article in detail for you to introduce the PHP for the static mode of opening, I believe that you have a certain understanding of the hope that your study has helped!

Related recommendations:

What is pseudo-static? PHP uses pseudo-static meaning?


PHP pseudo-Static text code detailed introduction


What is pseudo-static? Three ways to implement PHP pseudo-static

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.