Apache Open URL Rewrite function method

Source: Internet
Author: User

  1, calls about the rewrite module:
The URL rewrite in Apache 2.x is implemented through mod_rewrite.so, so you want to see if your Apache has been compiled into this module, And this module has been called in the Apache configuration file httpd.conf. In most mainstream distributions, the Apache 2.x is the rewrite module has been programmed in. For example, I'm using a slackware. The Apache 2.x configuration file is placed in the/ETC/HTTPD directory.

in httpd.conf, we find a row similar to the following, which is about the rewrite module, and the module name is mod_rewrite.so.

LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
or
LoadModule rewrite_module lib/apache2/ Modules/mod_rewrite.so If there is a # number in front of you, you should remove it. For most distributions, the Apache 2 module is typically located in the following two locations

/usr/lib/apache2/modules

or
/usr/lib/httpd/modules If you open the setting that calls Rewrite_module in httpd, check to see if it can be invoked, and view it by httpd-m parameters;

#/usr/sbin/httpd-m

If you find one of the following lines, Description The module has been able to be called

Rewrite_module (shared)

2, setting DocumentRoot directory:


in Apache 2.x, we'll see Docum Entroot the set of rows. This line is where the Web page is stored. For example, linuxsir.org is stored in the/opt/www directory. Then we will set the DocumentRoot as follows.

DocumentRoot "/opt/www" and then we have to do a targeted behavior setting for DocumentRoot. In general, the httpd.conf will give a default. If you want to change the path of DocumentRoot, but also to change the needleSettings for DocumentRoot Directory, which is the path set by the

<directory "DocumentRoot"

For example, we changed the DocumentRoot path to "/ Opt/www ", then we also want to make the directory to do targeted behavior settings to be changed to this path.

<directory/opt/www

Options followsymlinks
#AllowOverride None Note: Put the line in front of it and add the following line, which is a Llowoverride all
AllowOverride all
Order Allow,deny
Allow to all
</Directory> we take AllowOverride's ginseng The number is set to all, which means that URL rule overrides are supported on the entire server. The Apache server reads the. htaccess file in the root directory of each Web site. If this file is not available, or if the document does not define any rules about URL rewriting, it will not have any effect. In general, a mature Web server application suite supports URL rewriting, such as Drupal and Joomla. When we use these programs, we find that there is a file in the installation package in the. htaccess. After we have configured Apache, we just need to open this feature in the background of these programs.

3, restarting the HTTPD server:

In general, there are httpd server startup scripts in each release, such as
#/etc/rc.d/rc.httpd restart Note: Slackware Linux

#/etc/init.d/apache2 Restart Note: ubuntu, Debian, etc;
#/etc/init.d/httpd start Note: Fedora, Redhat, CentOS

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.