Enable and detect the rewrite function of the apacheRewrite module

Source: Internet
Author: User
Different Apache versions and operating systems often have different configuration file names and management methods. for example, the installation directory may be httpd or apache2, configuration file names and loading modules are often different, which may be regular for apache Officials. the configuration file naming and configuration management methods vary with Apache versions and operating systems, for example, the installation directory may be httpd or apache2, and the configuration file name and loading module methods are often different. it may be regular for apache officials, however, after all, most of our users are not network administrators. if we have nothing to do with apache configuration all day long, we are currently looking for information. generally, if the two file paths are incorrect, it will become very popular. Go to the topic.

By default, the Rewrite function of Apache is disabled, but its Rewrite module is loaded. Therefore, we should not just write it. the htaccess file always does not take effect. First, check whether apache has identified us. htacess.

I. check and confirm that the Rewrite module is loaded.

This article is tested on CentOS 6 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 you use the built-in command for installation, such as yum install or apt-get install, it cannot be found in httpd. conf/apache2.conf.

LoadModule rewrite_module modules/mod_rewrite.so

For this line, you can refer to the following settings to load the Rewrite module:

Run

sudo a2enmod rewrite

The Mod_rewrite module is enabled.

In addition, you can connect/etc/apache2/mod-available/rewrite. load to/etc/apache2/mod-enabled/rewrite. load to open the Mod_rewrite module. Instructions:

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

2. check and confirm that the directory Rewrite is enabled.

Loading the Rewrite library does not mean that our. htaccess file will take effect. you also need to enable the AllowOveride switch of the specified directory. the script is as follows:

     Options Indexes FollowSymLinks    AllowOverride All    Order allow,deny    Allow from all

AllowOverride can only be defined in the Directory Section. for specific usage, refer to the apache official instructions (below). The above scripts are generally placed in httpd. conf or/etc/httpd/conf. d/vhost. in conf, try to configure the website as much as possible:

....

Together to facilitate maintenance.

III. test the Rewrite function

The following is a. htaccess test instance:

# BEGIN
 
      RewriteEngine  on    RewriteBase /    RewriteRule .*$ 
 #END

Test Method: copy and save the file as. htaccess. upload the file to the root directory of the website. when you access any website path page, the file will jump to this blog, indicating that Rewrite has taken effect.

Related articles:

Rewrite settings of laravel framework in nginx

How to set iis pseudo-static on a windows Server (with rewrite Pseudo-static components)

Detailed Rewrite Pseudo-static rules for Nginx

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.