Apache: how to use the. htaccess file to perform pseudo-static processing on PHP websites or files

Source: Internet
Author: User
Apache: how to use the. htaccess file for PHP site or file pseudo static processing Source: http://www.ido321.com/1123.html

Today, I got a trick: use the. htaccess file to perform pseudo-static processing on PHP websites or files.

1. check whether the server supports pseudo-static processing:

The space must support Rewrite and the site directory must contain. the file parsing of htaccess is valid. find httpd in the apache installation directory. in the cof file, remove the # before LoadModule rewrite_module modules/mod_rewrite.so (approximately 154 rows, which is enabled by default)

2. search for the following parts in httpd. cof:

 Options FollowSymLinks AllowOverride None

Changed:

 Options FollowSymLinks AllowOverride All

If not, add it manually. (PS: LZ has tried. even if this is not available in the latest Apache version,. htaccess still takes effect. However, we recommend that you add)

3. restart the apache server and add the. htaccess file.

How to create a. htaccess file:

1. when saving the file, save the file as "***. txt", upload it to the server, and then rename it as ". htaccess" using FTP ". (For windows)

2. when saving the file, select the file?> Save as, select all files for the save type, and enter. htaccess for the file name. (For windows)

3. directly build on your Unix or Linux virtual host.

4. write it in Notepad, save it as a file name, open "command prompt" (CMD), and rename it, for example, rename c: \ htaccess.txt. htaccess

Note:. htaccess is required. save it as ANSI and upload in ASCII mode. it is best to set its permission to 644.

Generally. the htaccess file is placed in the root directory of the website to control the directory and all subdirectories. of course, it can also be placed in any sub-directory of the website, but if it is placed in a sub-directory, the commands in the subdirectory overwrite the commands in the more advanced directory or master server configuration file.

In the blog collection (http://www.ido321.com/1112.html) as an example, The Local. htaccess file is as follows:

# Rewriteengine: rewrite engine switch on: off: disable RewriteEngine On RewriteRule ^ index \. html $ index. phpRewriteRule ^ webmore \. html $ webmore. php

Use index.html instead of index. php webmore.html to replace webmore. php.

. Htaccess supports regular expressions, such:

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 Article: Miscellaneous: HTML 5 page visibility API

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.