Introduction: This is a detailed page about. htaccess configuration. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 342054 'rolling = 'no'>
1. Enable mod_rewrite
Set # loadmodule rewrite_module modules/mod_rewrite.so
This line # Remove
2. Modify httpd. conf
1) configure
Change AllowOverride none to AllowOverride all.
2) Modify options attributes
It is recommended to change to indexes followsymlinks.
Followsymlinks
The server allows a symbolic connection in this directory.
Indexes
If a URL mapped to a directory is requested and there is no directoryindex (for example, index.html) in the directory, the server returns a formatted directory list generated by mod_autoindex.
Note: Because the default value of options after apache2.2 is none, a 403 error occurs when. htaccess is enabled. This problem has been plagued for a long time because it was not noticed at first. All programs that cannot test the re_write function locally for a long time.
When I checked Apache error. log last night
[Sat Aug 09 23:06:19 2008] [Error] [client 127.0.0.1]
Options followsymlinks or symlinksifownermatch is off which implies
That rewriterule directive is forbidden: G:/hekey/www/111/post/0,
Referer: http: // localhost/111/admin. php? Go = misc_urlrewrite
The options issue is known only when the error occurs.
I have found many articles on how to configure Apache mod_rewrite on the Internet. I find this article useful. For more information, see.
1. view the environment configuration through the phpinfo () function provided by PHP, and find "loaded modules" Through Ctrl + F, which lists all modules enabled by apache2handler, if "mod_rewrite" is included, it is supported and you do not need to set it again.
If "mod_rewrite" is not enabled, open the directory your Apache installation directory "/Apache/CONF /"
Run Ctrl + F to find the "loadmodule
Rewrite_module ", and delete the" # "sign above. If not found, go to "loadmodule"
Add "loadmodule rewrite_module" to the last row.
Modules/mod_rewrite.so "(a must be exclusive), and then restart the Apache server.
2. Enable the Apache server to support ". htaccess"
How can I enable my local Apache server to support ". htaccess? In fact, you only need to modify the httpd. conf settings of Apache to enable Apache to support. htaccess. Open the httpd. conf file (where? In the conf directory of the Apache directory.
<Directory/>
Options followsymlinks
AllowOverride none
</Directory>
Change
<Directory/>
Options followsymlinks
AllowOverride all
</Directory>
You can.
3. Create a ". htaccess" file.
If it is on a Windows platform, I don't know how to create it at the beginning ". "htaccess" file, because this file does not actually have a file name and only has a file extension. You cannot create this file in a common way. Don't worry. I will tell you three methods right away:
Create an htaccess.txt text file first (of course, you can take the name of this text file as needed) in the three types of scripts, and rename the file in three ways: (1) use Notepad
Open the file, click "Save as", and enter ". htaccess" in the file name window. Note that the entire Green section contains English quotation marks, and click "save. (2) enter the CMD command
In the window, switch to the folder where the htaccess.txt file is just created through the cdswitch, and then enter the command: Rename htaccess.txt. htaccess
And then click Enter. (32.16connect to the folder where htaccess.txt is located through ftpand rename it through FTP software.
So how many ". htaccess" files need to be created, and what content should be entered in them? The basic principle is that the root directory must have one. All requests for redirection (URL rewriting) will be forwarded to index. php (
To the front-end Controller); "./Application" folder requires one to deny all direct access to the folder content (such
Http: // localhost/application/models/user. php ).
Question: for security, ". htaccess" in the "./library" folder must be the same as that in the previous folder; "./public", because all files in this folder are
For front-end direct access, so you need to cancel URL rewriting. The following are the content of Four "./htaccess" files:
./. Htaccess
Rewriteengine on
Rewriterule! /. (JS | ICO | GIF | JPG | PNG | CSS) $ index. php
./Application/. htaccess
Deny from all
./Library/. htaccess
Deny from all
./Public
Rewriteengine off
In fact, the URL rewriting function of Apache can also be set directly in the httpd. conf file, which is not detailed here. There are also many online tutorials.
Rewrite flag
R[= Code] (Force redirect) force external redirection
Force the replacement string to add http: // thishost [: thisport]/prefix to the external URL. If the code is not specified, the default 302 HTTP status code will be used.
F(Force URL to be forbidden) disables the URL and returns a 403http status code.
G(Force URL to be gone) if the force URL is gone, the response HTTP status code is returned.
P(Force proxy) force use of proxy forwarding.
L(Last rule) indicates that the current rule is the last rule, and the rule is overwritten after the analysis is stopped.
N(Next round) re-run the rewrite process from the first rule.
C(Chained with next rule) is associated with the next rule
If the rule matches, it is processed normally and the flag is invalid. If the rule does not match, all associated rules are skipped.
T= Mime-type (Force MIME type) force MIME type
NS(Used only if no internal sub-Request) is only used for internal subrequests
NC(No case) case insensitive
QSA(Query string append) append request string
Ne(No URI escaping of output) not escape special characters from the output
Example: rewriterule/Foo/(. *)/bar? Arg = p1/% 3d $1 [R, ne] will be able to correctly convert/Foo/zoo to/bar? Arg = p1 = Zed
PT(Pass through to next handler) passed to the next Processing
For example:
Rewriterule ^/ABC (. *)/DEF $1 [pt] # will be handed over to/DEF rules for processing
Alias/DEF/Ghi
S= Num (skip next rule (s) skips num rules
E= Var: Val (set environment variable) sets the environment variable
Server variables during rewrite:
HTTP headers: http_user_agent, http_referer, http_cookie, http_host, http_accept
Connection & request: remote_addr, QUERY_STRING
Server internals: document_root, server_port, server_protocol
System stuff: time_year, time_mon, time_day
Description of the rewrite rule expression:
. Match any single character
[Chars] matched string: chars
[^ Chars] unmatched string: chars
Text1 | string that can be selected by text2: text1 or text2
? Matches 0 to 1 Characters
* Matches 0 to multiple characters
+ Match 1 to multiple characters
^ String start flag
$ String end flag
/N Escape Character Mark
Reverse reference $ n is used to call the matching variable in rewriterule (0 <= n <= 9)
Reverse reference % N is used to call the last matched variable in rewritecond (1 <= n <= 9)
Rewritecond identifier
'Nocase | NC '(no case) Ignore size
'Ornext | or' (or next condition) logic or, multiple rewritecond conditions can be matched simultaneously
Applicable identifier of the rewriterule
'Redirect | r [= Code] '(Force redirect) force rewrite to an external redirection starting with HTTP (note URL changes) such as: [R = 301, l]
'Forbidden | f' (Force URL to be forbidden) is rewritten to prohibit access.
'Proxy | P' (Force proxy) is rewritten to the HTTP path accessed through the proxy
'Last | l' (last rule) indicates the last rewrite rule flag. If it matches, it will not be executed.
'Next | n' (next round) loops through the same rule until it cannot match
'Chain | C' (chained with next rule) If this rule is matched, the following chain-marked rule is continued.
'Type | T = mime-type' (Force MIME type) specifies the MIME type
'Nosubreq | ns' (used only if no internal sub-request)
'Nocase | NC '(no case) Ignore size
'Qsappend | qsa' (query string append) append the query string.
'Noescape | ne' (no URI escaping of output) disables characters in the URL from being automatically converted to % [0-9] +.
'Passthrough through to next handler 'applies the rewriting result to mod_alias
'Skip | S = num' (skip next rule (s) skips the following rules
'Env | E = var: Val '(set environment variable) to add Environment Variables
Actual Operation
Example:
Rewriteengine on
Rewritecond % {http_user_agent} ^ MSIE [NC, or]
Rewritecond % {http_user_agent} ^ opera [Nc]
Rewriterule ^. *-[F, L] Here "-" indicates no replacement. Visitors with IE and opera browsers will be banned from accessing the site.
Example:
Rewriteengine on
Rewritebase/test
Rewritecond % {request_filename}. php-F
Rewriterule ([^/] +) $/test/$ 1.php
# For example:/test/admin =>/test/admin. php
Rewriterule ([^/] +)/. html $/test/$ 1.php [l]
# For example:/test/admin.html =>/test/admin. php
Restrict directories to display images only
<Ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond % {request_filename }! ^. */. (GIF | JPG | JPEG | PNG | SWF) $
Rewriterule. * $-[F, L]
</Ifmodule>
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/342054.html pageno: 6.