Apache sets pseudo-static (Rewrite) in the httpd. conf configuration file)

Source: Internet
Author: User

The. htaccess file should be used when the content provider needs to change the server configuration for a specific directory without the root permission. If the server administrator is unwilling to modify the configuration frequently, you can allow the user to pass. the htaccess file modifies the configuration by itself, especially when the ISP runs multiple user sites on the same machine, and you want to change the configuration by yourself.
Even so, we should avoid using the. htaccess file as much as possible. Any configuration that you want to put in the. htaccess file can be placed in the main configuration file segment, and it is more efficient.
There are two main reasons to avoid using the. htaccess file.
First, performance. If AllowOverride enables the. htaccess file, Apache needs to find the. htaccess file in each directory. Therefore, whether or not it is actually used, enabling. htaccess will lead to performance degradation. In addition, you must read the. htaccess file once for each request.
In addition, Apache must be located in the directory of all superiors. htaccess file to make all valid commands take effect. Therefore, if you request a page in/www/htdocs/example, Apache must find the following file:

/. Htaccess
/Www/. htaccess
/Www/htdocs/. htaccess
/Www/htdocs/example/. htaccess

A total of four additional files are required to be accessed, even if none of these files exist. (Note that this may only be because the root directory "/" is allowed to use. htaccess, although this is not the case .)
Second, security. This will allow users to modify their own server configurations, which may lead to some unexpected modifications, so please carefully consider whether such privileges should be given to users. However, if users are given fewer privileges but cannot meet their needs, additional technical support requests will be generated. Therefore, users must be explicitly notified of their permissions, description: the value set by AllowOverride, and guide them to the corresponding instructions to avoid a lot of trouble in the future.

Note that placing commands in the. htaccess file under the/www/htdocs/example directory is exactly equivalent to placing the same commands in the middle section of the main configuration file.
We can know from the above, use. htaccess files have performance disadvantages, so we should avoid using them as much as possible. htaccess file, which is not used below. to perform pseudo-static operations on an htaccess file:

For Apache 1.x users, check whether the following two sections of code exist in conf/httpd. conf:
LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c

For Apache 2.x users, check whether the following code exists in conf/httpd. conf:
LoadModule rewrite_module modules/mod_rewrite.so

If it exists and starts with #, delete #. Then add the following code in the configuration file (usually conf/httpd. conf or conf/extra/httpd-vhosts.conf. Note that if the website is defined by a virtual host, you must add it to the virtual host configuration, that is, in progress. If you add it to the virtual host configuration, it may not be available. After modification, restart Apache.

Example

①. In apache % C5 % E4 % D6 % C3/"target =" _ blank "> apache configuration file httpd. conf, find:

The code is as follows: Copy code

LoadModule rewrite_module modules/mod_rewrite.so

Remove the comment symbol "#" from the front. If not, add the comment.
②. In the code:

The code is as follows: Copy code

Options FollowSymLinks
AllowOverride None

Add the pseudo-static code below (taking Wordpress pseudo-static as an example ):

The code is as follows: Copy code

RewriteEngine On
RewriteBase/
RewriteRule ^ index. php $-[L]
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule./index. php [L]

/Usr/local/apache/htdocs/wwwtest is the root directory of the website to be pseudo-static.

③ Restart apache

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.