Apache Rewrite module rewrite function opening and detection implementation

Source: Internet
Author: User
Apache version of different, operating system, its configuration file naming, configuration management methods are often different, such as the installation directory may be httpd, also may be apache2, the configuration file name and loading module mode is often different, perhaps for the official Apache is a regular, But after all, most of our users are not network management, nothing to configure Apache all day, are now used to find information, generally two file path is not always the fire big. Go to the chase.

The Apache default rewrite feature is disabled, but its rewrite module is loaded, so let's not just be busy writing. htaccess files, which always do not take effect, first check if our Apache has identified our. htacess.

One, check confirm rewrite module loading

This test is on the CentOS 6 system with the path:/etc/httpd/conf/httpd.conf

LoadModule Rewrite_module modules/mod_rewrite.so

If there is a comment above, remove it and restart Apache.
If the system comes with command installation, such as Yum Install or Apt-get install, cannot be found under httpd.conf/apache2.conf

LoadModule Rewrite_module modules/mod_rewrite.so

This line, you can refer to the following settings to load the rewrite module:

Executing in the terminal

sudo a2enmod rewrite

command, the Mod_rewrite module is enabled.

Alternatively, you can open the Mod_rewrite module by connecting the/etc/apache2/mods-available/rewrite.load to the/etc/apache2/mods-enabled/rewrite.load. The command operation is:

sudo ln-s/etc/apache2/mods-available/rewrite.load/etc/apache2/mods-enabled/rewrite.load

Second, check the confirmation directory rewrite open

Rewrite library loading does not mean that our. htaccess file will take effect, but also requires a special open allowoveride switch for the specified directory, as follows:

<Directory/var/www/>    Options Indexes followsymlinks    allowoverride all    Order allow,deny    allow From all</directory>

Where allowoverride can only be defined in the section of the directory, the specific usage can refer to the official Apache instructions (links below), the above script is generally placed in httpd.conf or/etc/httpd/conf.d/ Vhost.conf below, try to configure the site as much as possible:

<virtualhost ...> ....</virtualhost>

Defined together for easy maintenance.

Third, test rewrite function

The following is a. htaccess Test example:

# begin<ifmodule mod_rewrite.c>    rewriteengine  on    rewritebase/    rewriterule. *$ </ifmodule > #END

Test method, copy saved as. htaccess, upload to the site root directory, visit any path page of the site, will jump to this blog, indicating that rewrite has been in effect.

Related articles:

setting of Laravel frame rewrite under Nginx

IIS pseudo-static Setup method under Windows Server (with rewrite pseudo-static component)

Nginx detailed rewrite pseudo-static rule steps

  • 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.