PHP implementation Pseudo-static method summary, PHP pseudo-static summary
PHP pseudo-static use is mainly to hide the passed parameter name, the following gives you the implementation of the pseudo-static PHP method, see below for details.
Speaking of pseudo-static implementation of the scheme, you are not very quick to answer the "simple, configure the Apache rewrite rules on the line."
But have you found this situation, you recently made a lot of new features, a few new features every day, a lot of pseudo-static configuration every day, only to start two days of the students are also willing to cooperate, after two days of yun-dimensional students will scold. You paralysis, brain residue why not once finished, every day trouble me. But, you have to go online ah, have to hard to ask for the operation of the students, and then say a program ape the most shameless words, "This last change", and then change again, hey, your personality is sweeping ...
If there is such a problem, please look at the following article, to ensure that you do not seek the operation of the future, do what you want to do ...
How many ways does the PHP implement pseudo-static? Personal insights and Statistics Austria, there are four ways
1, the use of Apache URL rewrite rules, this everyone understand, in Apache configuration, here students are built, just list a simple configuration
Rewriteengine on
Rewriterule ^/test.html index.php?controller=index&action=test [L]
2, using PHP pathinfo, you do not have to see some sites such as playing ' www.xxx.com/index.php/c/index/a/test/id/100 ', of course to support this you need to put ' php.ini ' in the parameters
' Cgi.fix_pathinfo ' is set to 1. Take ' www.xxx.com/index.php/c/index/a/test/id/100 ' for example
echo $_server[' Path_info ']; Output '/c/index/a/test/id/100 '
Here, you should understand, you can parse this section, assign the actual address
3, using the 404 mechanism, the pseudo-static in general is the actual non-existent page, so you can use the Apache 404 configuration, but some problems, is the ' post ' type of request will be discarded, resulting in you cannot get ' $_post ',
But ' $_get ' is still available, assuming the 404 page here is ' 404page.php ', Apache is configured as follows:
ErrorDocument 404/404page.php
Then embed the following code in ' 404page.php '
Header ("http/1.1 OK"); There must be, otherwise the state is 404$requrl = $_server[' Request_uri ']; Request address/*** parse parameter from URL */function parseurlparams ($queryUrl) {$arr = explode ('? ', $queryUrl);p arse_str ($arr [1], $param); if ($param) {foreach ($param as $key = = $value) {$_get[$key] = $value;}}} Parseurlparams ($REQURL); URL parsing parameters//Then you can use $REQURL according to your own rules to match different actual request addresses if (Preg_match (' #^/test.html#is ', $REQURL, $matches)) {include (' index.php ');d ie ();}
4, Method 3 of the improved type, Method 3 in the Apache internal mechanism equivalent to redirect, resulting in post (get) passed parameters can not be obtained. Analysis above is actually not find the relevant files, that when the server can not find the relevant file, we specify a file for it, not OK, it does not jump, then post and so will not be lost. The Apache configuration is as follows:
Rewriteengine on
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewriterule. index.php
The general meaning of the above configuration is that when the requested file or directory cannot be found using the ' index.php ' substitution in the root directory, then you can get the relevant parameters in ' index.php ' and resolve to the actual request address
/*** gets the URI address of the current request * @param void* @author painsonline* @return string uri*/function Getrequri () {return trim ($_server[) Request_uri "]);} $reqUri = Getrequri (), if (Preg_match ('/^\/test.html/isu ', $reqUri)) {//Parse request address include ' test.php '; exit ();}
The above content to introduce the implementation of the pseudo-static PHP method, we hope to help.
Articles you may be interested in:
- PHP pseudo-Static code attached
- PHP pseudo-Static page functions attached to the use of the method
- Implement pseudo-static page code directly with PHP without mod_rewrite
- Four methods of passing parameter names in PHP pseudo-static hiding
- A detailed introduction to the implementation of PHP pseudo-static
- Introduction of PHP pseudo-static technology principle and Breakthrough principle realization
- thinkphp routing rules use examples to understand and pseudo-static functionality implementations (Apache overrides)
- PHP pseudo-Static Apache chapter
- PHP pseudo-Static IIS Chapter
- PHP pseudo static rewrite settings Apache Chapter
- Configuring pseudo-Static for PHP in Linux
http://www.bkjia.com/PHPjc/1091857.html www.bkjia.com true http://www.bkjia.com/PHPjc/1091857.html techarticle PHP Implementation of Pseudo-static method summary, PHP pseudo static summary of the use of PHP pseudo-static is mainly to hide the passed parameter name, the following to introduce the implementation of the pseudo-static PHP method, specific details please see ...