. Detailed details of htaccess configuration
1. Open Mod_rewrite
Will #loadmodule Rewrite_module modules/mod_rewrite.so
This line of the # get rid of
2. Modify Httpd.conf
1 Your Site directory configuration in the
AllowOverride None to allowoverride all
2 Modify the properties of options
Proposed change to indexes FollowSymLinks
FollowSymLinks
The server allows symbolic connections to be used in this directory.
Indexes
If a URL mapped to a directory is requested and there is no directoryindex (for example, index.html) in this directory, the server returns a formatted list of directories generated by Mod_autoindex.
Note: Since the current apache2.2 version, the default value of the options is none, resulting in a 403 error after htaccess. This problem has been bothering me for a long time because I didn't notice the problem at first. Any program that is unable to test re_write functionality locally for a long time.
When I saw Apache's Error.log last night,
[Sat Aug 09 23:06:19 2008] [ERROR] [Client 127.0.0.1] Options followsymlinks or SymLinksIfOwnerMatch are off which implies this rewriterule directive is forbidden:g:/hekey/www/ 111/post/0, referer:http://localhost/111/admin.php tutorial? go=misc_urlrewrite
When you're wrong, you know it's a matter of options.
--------------------------------------------------------------------------------
On the internet to find a lot of articles about the configuration of Apache Mod_rewrite, found this article most useful, we need to refer to.
1, through the phpinfo () function of PHP to view the environment configuration, through the ctrl+f find "Loaded Modules", which lists all apache2handler have been open modules, if it includes "Mod_rewrite", has been supported, You no longer need to continue setup.
If "Mod_rewrite" is not turned on, open the directory under your Apache installation directory "/apache/conf/" under the httpd.conf file, through ctrl+f find "LoadModule rewrite_module", the previous " # "number deleted." If it is not found, go to the LoadModule area, add "LoadModule rewrite_module modules/mod_rewrite.so" (the required exclusive line) on the last line, and then restart the Apache server.
2, let the Apache server support ". htaccess"
How do I get my local Apache server to support ". htaccess"? In fact, as long as a simple change to the Apache httpd.conf settings can let Apache support. htaccess. Open the httpd.conf file (where?) Apache directory, with a text editor open, find
<directory/>
Options FollowSymLinks
AllowOverride None
</Directory>
To
<directory/>
Options FollowSymLinks
AllowOverride All
</Directory>
It's okay.
3, establish the ". htaccess" File
If it is under the Windows platform, at the beginning really do not know how to build ". htaccess" file, because this file does not actually have a filename, only the extension, through the normal way is not able to create this file, do not worry, immediately tell you three ways:
Three methods are to create a htaccess.txt text file (of course, the name of the text file you can arbitrarily take), and then there are three ways to rename the file: (1) With Notepad Open, click the file-Save as, in the filename window input ". htaccess", Note that the entire green section, which contains the English quotes, is then clicked to save the line. (2) Enter the cmd command window, switch on CD when you have just established the Htaccess.txt file folder, and then enter the command: Rename Htaccess.txt. htaccess, then click the Keyboard enter button. (3) through the FTP connection Htaccess.txt folder, through the FTP software rename.
So what do we need to build a few ". htaccess" files and what do we enter? The basic principle is that the root directory must have one, for redirects (URL overrides) all requests will go to index.php (to the front controller), and the "./application" folder requires one to deny all direct access to the contents of the folder (such as HTTP ://localhost/application/models/user.php), because all access requests must be assigned access through the front-end controller, followed by security, under ". htaccess" in the "./library" folder. Public folder must be selected, because the files for this folder are all directly accessible to the front end, so you need to undo the URL rewrite. The following is the contents of 4 "./htaccess" Files:
./.htaccess
Rewriteengine on
Rewriterule!/. (js|ico|gif|jpg|png|css tutorial) $ index.php
./application/.htaccess
Deny from all
./library/.htaccess
Deny from all
./public
Rewriteengine off
In fact, the Apache URL rewrite function can also be set directly in the httpd.conf file, here is not specific, there are many tutorials on the web.
--------------------------------------------------------------------------------
Rewrite logo
R[=code] (force redirect) forces external redirection
to force a URL that is redirected to an external string, plus a http://thishost[:thisport]/prefix. If code is not specified, the default 302 The HTTP status code.
F (force URL to is forbidden) disables the URL and returns a 403HTTP status code.
G (force URL to is gone) forces the URL to gone and returns a 410HTTP status code.
P (Force proxy) forces the use of proxy forwarding.
L (last rule) indicates that the current rule is the final one, stopping the rewrite of the rule after parsing.
N (next round) starts the rewrite process again from the first rule.
C (chained with next rules) is associated with the next rule
if the rule match is normal, the flag is invalid, and if it does not match, all of the following associated rules are skipped.
T=mime-type (Force MIME type) enforces MIME types
NS (used only if no internal sub-request) is used only for not internal child requests
NC (no case) does not distinguish between large lowercase
QSA (query string append) Append request string
NE (no URI escaping of output) is not an output escape special character
For example: rewriterule/foo/(. *)/bar? arg=p1/%3d$1 [R,ne] will be able to correctly convert/foo/zoo to/bar?arg=p1=zed
PT (passes through to next handler) passed to the next processing
For example:
Rewriter Ule ^/abc (. *)/def$1 [PT] # will be given to the/def rule processing
Alias/def/ghi
S=num (skip next rule (S) skips the NUM Bar rules
E=var:val (set en Vironment variable) Set environment variable
Server variable when 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 word character
[chars] matching string: chars
[^chars] does not match string: chars
TEXT1|TEXT2 selectable string: Text1 or Text2
? Match 0 to 1 characters
* Match 0 to more characters
+ match 1 to more characters
^ String Start flag
$ string End Flag
/n Escape Character flag
Reverse reference $N variable invocation for matching in rewriterule (0 <= N <= 9)
Reverse reference%N for the last matching variable call in Rewritecond (1 <= N <= 9)
Rewritecond Marker
' Nocase| NC ' (no case) ignores size
' Ornext| or ' (or next condition) logic or, you can match multiple rewritecond conditions at the same time
Rewriterule the applicable identifier http//:www.111cn.net
' Redirect| R [=code] ' (Force redirect) forced overrides to an external turn based on HTTP (note URL changes) such as: [R=301,l]
' Forbidden| F ' (Force URL to is forbidden) overridden to prohibit access
' Proxy| P ' (force proxy) overrides the HTTP path that is accessed through the proxy
' Last| L ' (last rule) The final rewrite rule flag, if matched, no longer executes subsequent rules
' Next| N ' (next round) loops the same rule until the match is not met
' Chain| C ' (chained with next rule) if the rule is matched, continue with the following rules with the chain flag.
' Type| T=mime-type ' (Force MIME type) specifies MIME type
' Nosubreq| NS ' (used only if no internal sub-request) skipped if it is an internal child request
' Nocase| NC ' (no case) ignores size
' Qsappend| QSA ' (query string append) append query strings
' Noescape| NE ' (no URI escaping of output) prevents characters in a URL from automatically escaping into a%[0-9]+ form.
' Passthrough| PT ' (pass through to next handler) applies the rewrite results to Mod_alias
' Skip| S=num ' (skip next rule (s)) skip the following few rules
' Env| E=var:val ' (Set environment variable) 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 "-" means no replacement, browsers for IE and opera visitors will be barred from accessing.
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
Restricted directories can only display pictures
< Ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{request_filename}!^.*/. (gif|jpg|jpeg|png|swf) $
Rewriterule. *$-[f,l]
</ifmodule>