1. htaccess File Usage Prerequisites
The main function of htaccess is to implement URL rewriting, that is, when the browser through the URL access to a server folder, as the owner, we can receive this URL, specifically how to receive it, is the role of this file. All accesses are implemented via URLs, so. The role of the. Htaccess is trivial. Because of this, so the general site by setting. htaccess, which attracts users through a very friendly URL, then uses. htaccess to take the user to a location that needs to be accessed.
To use this powerful feature, you have to open the rewrite module inside Apache.
The previous article has talked about Windows and Ubuntu open rewrite modules using. htaccess.
In fact, the general steps to open the module are the same, both Windows and Linux.
2. Introduction to basic grammar of htaccess
Turn on rewrite engine: Rewriteengine on
To set the root of an override: Rewritebase/-Description: Because this folder is defined, the corresponding substitution has a reference.
Match all eligible requests: Rewritecond-Description: Rewritecond defines a set of rule conditions, which can have one or more, only if the URL that the user comes to meets these conditions. Our. htaccess only start receiving, otherwise the user will go directly to access the required directory.
For example, in order to allow search engines to crawl more of our pages and avoid repeated scratching, we usually redirect the domain name without www to www.XXX.com, which realizes this function as follows:
Rewriteengine on
Rewritecond%{http_host} ^nbphp\.com$ [NC]
Rewriterule ^ (. *) $ http://www.nbphp.com/$1 [r=301,l]
The previous example redirects nbphp.com to www.nbphp.com
%{http_host} refers to the primary domain name of the URL that gets the user's access and then the space is followed by a regular expression match, and the consciousness is whether it is nbphp.com.
If a user accesses a URL that satisfies all of the listed rewritecond conditions, then the next rewriterule starts with booting, which starts to implement the important functionality of the. htaccess file.
Similarly, the preceding is the regular expression, the user analyzes the user's except the primary domain name nbphp.com the URL, ^ (. *) $ means all content. Then the space is written in the directory we guide the user to visit, we take him to a new domain name. $ = refers to the contents of the preceding brackets that match the URL.
This is a complete and small example. We can refer to this article about how to invoke a part of the URL in Rewritecond (Apache mod_rewrite Learning (Rewritecond rewrite rules);
File Source: http://www.cnblogs.com/yyl8781697/articles/php-htaccess.html
PHP Framework. htaccess file Role