Apache: How to use a. htaccess file for pseudo-static processing of a PHP Web site or file

Source: Internet
Author: User

Source: http://www.ido321.com/1123.html

Today get a trick: Use the. htaccess file to perform pseudo-static processing of a PHP Web site or file.

First, check whether the server supports pseudo-static processing:

You must have space support Rewrite and file parsing for. htaccess in the Site directory. Locate the Httpd.cof file in the Apache installation directory and remove LoadModule rewrite_module modules/mod_ Rewrite.so in front of the # (about 154 lines, my default is to open)

Second, find the following sections in HTTPD.COF:

<directory/>   Options followsymlinks   allowoverride none</directory>

Switch

<directory/>   Options followsymlinks   allowoverride all</directory>

If not, add it manually. (Ps:lz tried, even without this on the recent new version of Apache,. htaccess is still in effect.) But different server and version of the reason, the proposed addition )

Third, restart the Apache server and add the. htaccess file

How to create the. htaccess file:

1, save the file when the document saved fame as "***.txt", and then upload it to the server, and then directly using the FTP software to rename to ". htaccess". (for Windows)

2, save the file when you choose File-Save As, saving type Select all files, and then enter the file name. htaccess. (for Windows)

3. Build directly on your UNIX or Linux virtual host.

4. Write with Notepad, save it as a file name, then open the command Prompt (CMD), and then use the Rename command (rename), for example: rename C:\htaccess.txt. htaccess

Please note:. htaccess must be saved in ANSI format and uploaded in ASCII mode, preferably with the permission set to 644.

in general, we place the. htaccess file at the root of the Web site, control the directory and all subdirectories, and of course can be placed in any subdirectory of the site, but if placed in subdirectories, directives in subdirectories overwrite higher-level directories or instructions in the master server configuration file.

In the blog ingest set (http://www.ido321.com/1112.html), for example, the local. htaccess file is as follows:

#rewriteengine为重写引擎开关on为开启off为关闭 rewriteengine on Rewriterule ^index\.html$ index.phprewriterule ^webmore\.html$ webmore.php
Replace webmore.php with index.html instead of index.php webmore.html. The . htaccess supports regular expressions, such as:

original news/detail.php?id=2 pseudo-static news/detail_2.html

Rewriterule ^news/detail_ ([0-9]{1,}) \.html$ news/detail.php?id=$1


Next: Talk: HTML 5 page Visibility API

Apache: How to use a. htaccess file for pseudo-static processing of a PHP Web site or file

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.