Using pseudo-static _php tutorials in PHP

Source: Internet
Author: User
The last simple to say the use of the PHP expression, this time the regular expression can be useful, learning pseudo-static need to be able to use the regular expression, then pseudo-static and true static difference is what, I think it should be pseudo-static can save disk space, conducive to SEO, The access speed is not as fast as true static. Pseudo-Static is also the use of Apache rewrite mechanism, come down to share it

1. Use pseudo-static first to confirm open rewrite module

First open httpd.conf, find LoadModule rewrite_module modules/mod_rewrite.so Remove the previous # can restart Apache, use Phpinfo to confirm the rewrite module successfully enabled

Seeing the red one means that rewrite has been successfully enabled <喎?http: www.bkjia.com="" kf="" ware="" vc="" "="" target="_blank" class="keylink"> vcd4kpha+pgjypgo8l3a+ cjxwpjiuyrntw86xvrlmrnkqz8ju2krpcmvjdg9yecdvvnpsu77kqwxsb3dpdmvycmlkzsbbbgw8l3a+cjxwptxi0ru+5l/ j0ts809tayxbhy2hltcrodgrvy3o1xerpcmvjdg9yeb3atepa77vy1d/q6cti1ve7+ rxerglyzwn0b3j5vdq148dvpc9wpgo8cd48chjlignsyxnzpq== "Brush:java;" > Options Indexes followsymlinks allowoverride all Order allow,deny enable pseudo-static rewrite rules after the Direc Tory node, it can also be written in a separate. htaccess file, which I strongly recommend using the following method

3.apache Specify the first page, error page

First create a new. htaccess file, generally create a new Xx.txt file Save As can, this file I put in the root directory of the project, the contents of this file is as follows

DirectoryIndex index.php
ErrorDocument 404/static2/404.php

The following first Test 404, we first visit a non-existent PHP to see 404 Effective No, this is my error page

 
  

Here is the run

The HTML of the homepage is as follows

 
  System HomeWelcome

We direct the address to the root directory, we can see the home page after the return

There is a situation to consider that is the time of the visit Apache list directory structure problem, in fact, is very simple in. htaccess plus an options None, it should be noted that the options are not configured in the directory, or there will be a 403 error


4. Pseudo-Static use

http://localhost/static2/ view-sports-id5.html similar to this URL we should have seen a lot of, this is a pseudo-static URL, we seem to access a static HTML but actually not, like this URL like sports and ID 5 is probably the program to use the parameters, we access is actually a Dynamic pages. This is more conducive to SEO, the following section of the configuration for everyone to see

 
  
   
  Rewriteengine on Rewriterule view-([a-za-z_]+)-id (\d+) \.html news.php?type=$1&id=$2
 
  

Rewriteengine on means the Apache rewrite engine is enabled.

Rewriterule represents a rewrite rule, and the first space behind the regular specification is the PHP page that is actually accessed, which represents the value of the first subexpression in the preceding regular specification, and so on, and so on. So we can get the value of the parameter in news.php.

The same is true if the controller can also write a. htaccess in the appropriate folder, followed by our rewrite rules


5. Use. htaccess to control access rights

In the daily development we may write in the project DAO, Controller, tool class This large heap of PHP, and these files we do not want others to access through the browser, this situation using the session to limit does not seem to work, this situation using rewrite rules is very simple

Rewriterule [a-za-z0-9_]+\.class\.php 403.html

So write a sentence outside the program access to jump to another page, to achieve the control of access

Use of 6.RewriteCond

Sometimes we need to judge the use of rewriting in some cases, which is to use Rewritecond, for example, we can tell if the request is not a file (or a nonexistent file), and if the condition is met, the rewrite rule will be executed.

#如果请求的不是一个文件
Rewritecond%{request_filename}!-f
#并且不是一个目录
Rewritecond%{request_filename}!-d
Rewriterule ccc.html index.php

This configuration means that if the requested ccc.html is not present, it jumps to index,php

And look at the last configuration.

 
  
   
  Rewriteengine on# How do you know, this request is www.hsp.com sent. referer# If you are requesting a JPG image, it is forbidden to Rewritecond%{http_referer}!www.hsp.com  rewriterule. *\.jpg-[f]
 
  
[F] means no access, other comments should be able to read


Finally, the daily development of not all the pages are to be static, such as back-office systems, fund stocks and other requirements of real-time high-quality pages or websites, real-time phone calls or traffic query page, education query page is not suitable for static, corresponding content is relatively stable, such as the nature of the website home can consider the use of true static, If you do not want to use the true static but also want to facilitate the SEO pseudo-static should be a good choice.



http://www.bkjia.com/PHPjc/621636.html www.bkjia.com true http://www.bkjia.com/PHPjc/621636.html techarticle The last time to simply say the use of the PHP expression, this time the regular expression can be useful, learning pseudo-static need to be able to use the regular expression, then pseudo-static and ...

  • Related Article

    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.