Between management introduction
Apache Module Mod_rewrite
An engine that describes a real-time rewrite URL request based on a certain rule
State extension (E)
Module name Rewrite_module
Source file mod_rewrite.c
Compatibility is available only in Apache 1.3 and later versions
Overview
This module provides a rewrite engine based on the regular expression parser to rewrite URL requests in real time. It supports a flexible and powerful URL manipulation mechanism for each complete rule that can have an unlimited number of child rules and additional conditional rules. This URL action can depend on a variety of tests, such as server variables, environment variables, HTTP headers, time tokens, and even a lookup database of various formats that match the components of a URL.
This module can manipulate all parts of the URL, including the Path Information section, at both the server-level (httpd.conf) and directory-level (. htaccess) configurations, and generate the final request string. The result of this rewrite operation can be an internal child processing, or an external request, or even an internal proxy processing.
However, all of these features and flexibility pose a problem, which is complexity, so don't expect to be able to read the entire module within a day.
For more discussion, details, and examples, see the detailed URL rewrite document.
In most cases, it is used in conjunction with the. htaccess file. For example, the URL of this article (http://dancewithnet.com/2010/05/29/making-mod-rewrite-and-htaccess-work-on-mac-os-x) is WordPress with MoD The rewrite module is implemented with the. htaccess file, known as a fixed link (permalinks).
Windows
Under Windows, we typically use the administrator account, so enabling these two is simple:
1. In the [Apache installation directory]/conf/httpd.conf find #loadmodule rewrite_module modules/mod_rewrite.so, remove the previous annotation symbol #. If this line is not in use, add it. Verify that the mod_rewrite.so file is in the Modules folder under the Apache installation directory. This enables the MoD rewrite feature.
2. Found in the Apache installation directory]/conf/httpd.conf
The code is as follows |
Copy Code |
<directory/> Options FollowSymLinks AllowOverride None Order Deny,allow Deny from all </Directory> |
Change "allowoverride None" to "allowoverride all" so that all folders are supported. htaccess, or enabled for the specified folder. htaccess, can be installed in the Apache directory]/conf/ Join in httpd.conf
The code is as follows |
Copy Code |
<directory "d:/sites/example/" > Options Indexes FollowSymLinks AllowOverride All Order Allow,deny Allow from all </Directory> |
This approach is typically configured with a virtual host, so most of the configuration code will be written to the [Apache installation directory]/conf/extra/httpd-vhost.conf, which is much clearer and easier to manage.
3. Restart Apache, OK.
After completing the appeal procedure, WordPress will use the link settings in the permalink in WordPress, in addition to the default settings, and the htaccess can be generated directly in its installation directory.
Mac OS X
Instead of using the root account in Mac OS X, you get root-related permissions through sudo. In general, we put the Web site files in a personal directory, such as ~/sites, so that the rights of Mac OS management, compared to Windows, a lot more complicated.
1. In the terminal run sudo vi/etc/apache2/httpd.conf, find #loadmodule rewrite_module modules/mod_rewrite.so, remove the previous annotation symbol #.
2. Run sudo vi/etc/apache2/extra/httpd-vhost.conf, join
The code is as follows |
Copy Code |
<directory "/users/[username]/sites" > Options Indexes followsymlinks MultiViews AllowOverride All Order Allow,deny Allow from all </Directory> |
So the whole ~/sites can support. htaccess.
3. Run sudo vi/private/etc/apache2/users/[username].conf, the allowoverride none of which changed to allowoverride all. It should be noted that the previous version of Mac OS X, the path might be/private/etc/httpd/users/[username].conf
4. In the directory you want to create a new. htaccess, and modify its permissions to 777, here is still the use of WordPress fixed link for example.
CD ~/sites/wordpress
Touch. htaccess
chmod 777. htaccess the permission to create a new file defaults to 644, which can be seen by Ls-l. htaccess, which is not automatically written to. htaccess, which is more secure, but requires manual writing.
5. Restart Apache:sudo apachectl after exiting restart
Once you have finished this setup, you can use the fixed link feature of WordPress. Note that if. htaccess is copied directly from Windows, there may be an error in the </IfModule> without matching <IfModule> section in the log. The simple solution is to create a new file and copy the paste again.