Home  >  Article  >  Backend Development  >  Implementing static URL in PHP_PHP tutorial

Implementing static URL in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:54:38856browse

php tutorial to achieve static url

PHP implements pseudo-static

The other is the pseudo-static method, that is, what users and search engines see is a static page with the .html suffix, but in fact it is still a dynamic program, but it is disguised in some way.

There are also two ways to implement this method:

The first one is to use the web server to perform url rewrite to make the link static. Let’s take apache as an example to explain how it is implemented. For users with server configuration permissions, it is recommended to use the mod_rewrite module of apache. It is assumed that the mod_rewrite module has been installed. Open the apache configuration file, find the corresponding host section, and add the following code:

rewriteengine on
rewriterule ^/abc/([a-z]+)/([0-9]+).html$ /abc.php?action=$1&id=$2


Then execute service httpd reload in the shell and let apache reload the configuration.

But for most of us, what we buy is just space and we have no permission to modify the apache configuration file. Is there no way? No, of course there is a way. First, we enter the root directory of our space (such as public_html), and then create a file named .htaccess. The content of this file is basically as follows:

rewriteengine on
rewritebase /
rewriterule ^post/([0-9]+).htm read.php?1
rewriterule ^post/([0-9]+)_([0-9]+).htm read.php?1&page=2
rewriterule ^post/([0-9]+)_([0-9]+)_([0-9]+).htm read.php?1&page=2&=3

How to write php program

function mod_rewrite(){
If ( isset ( $_server [ ’ path_info ’ ])){
$ Url = substr ($ _Server [’Path_info’], 1);
$ URL = Explode (’ /’, $ url);
foreach ( $url as $key => $value ){
If ( $key % 2 != 1 ){
If ( $value != ’’ ) $_get [ $value ] = $url [ $key + 1 ];
$querystring [] = $value . ’ = ’ . $url [ $key + 1 ];
                                                                                                          }                 }
​​​​​​​​​​ $_server [ ’ php_self ’ ] = substr ( $_server [ ’ php_self ’ ]

, 0 , strpos ( $_server [ ’ php_self ’ ] , ’ .php ’ ) + 4 );

$_server [’request_uri’] = $_server [’php_self’]


. ’ ? . $_server [ ’ query_string ’ ];

}

}

http://www.bkjia.com/PHPjc/631739.html

truehttp: //www.bkjia.com/PHPjc/631739.htmlTechArticlephp tutorial to implement url static php to implement pseudo-static Another way is pseudo-static, that is, users and search engines see What you get is a static page with the .html suffix, but in fact it is a dynamic program,...
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