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