Apache configuration rewrite and. htaccess Files (reproduced)

Source: Internet
Author: User

Today saw a friend of the post sent a rewrite post, previously also wrote a, configuration is very simple, but did not pay attention to this problem, then did not use. htaccess file, tested on the machine, found that really can not use, so began to find the problem.

I built it from scratch:

1. First determine the version of Apache you are using and whether the Mod_rewrite module is loaded.

Simple method Echo phpinfo (); See if there's any rewrite in Apache's mod.

If you have skipped this step

For Apache 1.x users, check the conf/httpd.conf for the following two snippet codes:

LoadModule Rewrite_module libexec/mod_rewrite.so

Addmodule mod_rewrite.c

For Apache 2.x users, check if the following code is present in conf/httpd.conf:

LoadModule Rewrite_module modules/mod_rewrite.so

Note: If there is a # in front, remove it. and ensure that your Apache file has the mod_rewrite.so file (1.X version of mod_rewrite.c).
2. Configure Apache configuration file httpd.conf implementation rewrite

Found it

<ifmodule mod_rewrite.c>

</IfModule>

Do not add yourself and then write your rewrite rules, for example:

<ifmodule mod_rewrite.c>
Rewriteengine on
Rewriterule ^test.htm$ test.php
</IfModule>

3. It is important to note that if the Web site is defined by a virtual host, be sure to add to the virtual host configuration, that is, <VirtualHost>, if the addition of the virtual host configuration will probably not be able to use, restart the Apache,rewrite configuration is finished.

4. Let Apache support. htaccess

Remove the code from the <ifmodule mod_rewrite.c>.

Found it

<directory/>

Options FollowSymLinks

AllowOverride None

</Directory>

Change the allowoverride None inside to allow Override all so that the. htaccess file can be enabled.

5. Create a. htaccess file, win under can be built with notepad++ such as editor (Notepad not), if too troublesome this document attachment, put in the project directory, and then write their own rules in the inside.

Rewriteengine on
Rewriterule ^test.htm$ test.php

6. Restart Apache.

7. General Apache above configuration on the line, but my not yet, so studied the Apache configuration file found such a parameter:

Accessfilename access.ht

The meaning is; Accessfilename defines the file name of the access control file under each directory, the default is. htaccess (most people are just. htaccess, so a lot of online tutorials have not written this step, and my is access.ht), you can change this file, To change the access control limits for different directories.

Change it to

Accessfilename. htaccess

8. Restart Apache on the line.

Outside:. htaccess location Issue: The htaccess file (or "Distributed Profile") provides a way to change the configuration for each directory by placing a file containing instructions in a specific directory that acts on this directory and all its subdirectories. (You can have a. htaccess file under each folder)

Reprinted from: http://www.cnblogs.com/banruo/archive/2010/11/02/1867536.html

Apache configuration rewrite and. htaccess Files (reproduced)

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.