Linux Apache Open URL Rewrite method (detailed description) _linux

Source: Internet
Author: User
Linux to open URL rewriting method:

1, open Apache httpd.conf (usually in the/etc/httpd/conf directory)

2, find #LoadModule rewrite_module modules/mod_rewrite.so Remove the front of the #

3, to find allowoverride None changed to allowoverride all, have two completely get rid of

Note: The allowoverride parameter is set to all, which means that URL rule overrides are supported on the entire server. The Apache server reads the. htaccess file under the directory under each Web site. Without this file, or if the document does not define any rules about URL rewriting, there is no effect.

Restart Apache (with command: Service httpd restart).

Apache Open URL Rewrite function method detail

1, about the rewrite module of the call:
URL rewriting in Apache 2.x is done 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 Apache's 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 will 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 # on the front, you need to 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 of the call Rewrite_module in httpd, check to see if it can be called by httpd-m parameters;

#/usr/sbin/httpd-m

If the following line is found, the module can already be invoked

Rewrite_module (Shared)

2. Set up DocumentRoot directory:


In Apache 2.x, we see a row of documentroot settings. 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" then we have to do to the documentroot of targeted behavior settings. In general, the httpd.conf will give a default. If you want to change the DocumentRoot path, also change to the DocumentRoot directory settings, which is

<directory "DocumentRoot set path" >

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

<directory "/opt/www" >

Options FollowSymLinks
#AllowOverride None Note: Add the # to the front of the line, then add the following line, which is allowoverride all
AllowOverride All
Order Allow,deny
Allow from all
</Directory> we set the allowoverride parameter to all to indicate that the 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, restart the httpd server:

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

#/etc/init.d/apache2 Restart Note: Ubuntu, Debian and so on;
#/etc/init.d/httpd Start Note: Fedora, Redhat, CentOS
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.