Setting of the Zend framework (Apache/rewrite rule notation)

Source: Internet
Author: User
Tags regular expression response code nginx server zend zend framework

Edit the C:windowssystem32driversetchosts file to add a field, such as 127.0.0.1 audit.local
Modify Apache configure files, in the XAMPP environment is under the D:/xampp/apache/conf directory, first edit the httpd.conf, open the Rewrite module: This line of comments removed: LoadModule rewrite _module modules/mod_rewrite.so and then edit the extra/http-vhosts.conf file, adding the following lines:
<virtualhost *:80>
DocumentRoot "d:/xampp/htdocs/"
ServerName localhost
ErrorLog Logs/localhost.error_log
Customlog Logs/localhost.access_log Common
</VirtualHost>
<virtualhost *:80>
DocumentRoot "d:/xampp/audit/public/"
ServerName audit.local
ErrorLog Logs/audit.error_log
Customlog Logs/audit.access_log Common

Rewriteengine off
<location/>
Rewriteengine on
Rewritecond%{request_filename}!-f
Rewriterule!. (JS|ICO|GIF|JPG|JPEG|PDF|PNG|CSS) $/index.php
</Location>
<directory "D:/xampp/audit/public" >
#Allow Server side include,cgi, disable directory index
Options followsymlinks Includes execcgi
Order Allow,deny
Allow from all
</directory>
</VirtualHost>
Then remove the comment from the Namevirtualhost line and restart Apache to start using the


More about the Apache rewrite rule of the writing and description.

Rewrite engine will parse each rewrite rule, each rewrite rule can be brought with or without rewrite condition, with words written before the rewrite rule. If the rewrite rule is met, the rewrite condition will be examined further. The specific processing is as follows:

First match the rewrite Patern, and if not, enter the next rewrite rule.

If it matches, then mod_rewrite checks rewrite condition, and if there is no condition, the new string replaces the URL and then goes to the next rewrite rule.

If the rewrite condition exists, check the conditions in order. Condition matches are not for URLs, but for extension variables. Conditons is the default relationship between and, which means that the conditon exits the match whenever there is a mismatch, and when a condition is matched, the next one is checked until it does not match, and if all the conditions match, the substitution takes place.

Test conditions:

-f file exists;-d directory exists;-L is a linked file (symbol link); s file is 0

Parameters of rewrite rule:

Rewritecond instruction Format
Syntax: Rewritecond teststring Condpattern
1 TestString is a plain text string, but can contain an extensible component
2 Condpattern is conditional pattern, a regular expression applied to the current instance teststring, that is, teststring will be computed and then matched to Condpattern.
3 In addition, you can also append special flags [flags] to Condpattern as the third parameter of the rewritecond instruction. Flags are a comma-delimited list of the following tags:
' Nocase| NC ' It causes the test to ignore case, that is, teststring and Condpattern no case checking
' Ornext| Or ' it combines the conditions of several rules with or, not the implied and.

Rewriterule directives
Syntax: Rewriterule pattern substitution
1 pattern is a Perl-compatible regular expression that acts on the current URL. The "current" here refers to the value of the URL when the rule is in effect.
2 substitution is a string that replaces (or replaces) the original URL when it matches the pattern.
3 In addition, substitution can also append special tags [flags] as the third parameter of the rewriterule instruction. Flags are a comma-delimited list of the following tags:
' Redirect| R [=code] ' (Force redirect redirect)
Substitution that are prefixed with http://thishost[:thisport]/(making the new URL a URI) can be enforced by an external redirect. If code is not specified, an HTTP response code of 302 (temporary move) is generated. If you need to use another response code in the range 300-400, just specify this value here, and you can also use one of the following symbol names: Temp (default), permanent, seeother. It can be used to feedback the normalized URL to the client, such as rewriting "/~" as "/u/", or/u/user plus slashes, and so on.

Note: When using this tag, you must ensure that the replacement field is a valid url! Otherwise, it will point to an invalid location! And keep in mind that this tag itself is simply a prefix to the URL plus http://thishost[:thisport]/, and the override operation continues. Typically, you will want to stop the rewrite and redirect immediately, and you'll also need to use the ' L ' tag.

' forbidden| F ' (force URL to prohibited forbidden)
forces the current URL to be banned, that is, immediately feedback an HTTP response code 403 (forbidden). With this tag, you can link several rewriteconds to conditionally block certain URLs.
' gone| G ' (force URL to obsolete gone)
forces the current URL to be obsolete, that is, to immediately feedback an HTTP response code 410 (deprecated). Using this tag, you can indicate that the page has been discarded and no longer exists.
' proxy| P ' (force proxy proxy)
This tag causes the substitution component to be internally coerced to the proxy request, and immediately (that is, an immediate interruption of the override rule processing) transfers the processing to the agent module. You must make sure that this replacement string is a valid URI, such as a common http://hostname, that can be processed for the Apache proxy module. With this tag, some remote components can be mapped to the local server namespace, thereby enhancing the functionality of the Proxypass directive.
Note: To use this feature, the agent module must be compiled in the Apache server. If you are unsure, you can check the output of "httpd-l" for mod_proxy.c. If so, mod_rewrite can use this feature, and if not, you must enable Mod_proxy and recompile the HTTPD program.

' last| L ' (Final Rule last)
Stop the rewrite immediately and apply no more override rules. It corresponds to the last command in Perl or the break command in the C language. This tag prevents the currently overridden URL from being overridden by its successor rule. For example, use it to rewrite the URL of the root path ('/') for the URL that actually exists, such as '/e/www/'.
' next| N ' (re-execute next round)
Redo The rewrite operation (starting from the first rule). The URL that is processed again is not the original URL, but the URL that is processed by the last overriding rule. It corresponds to the next command in Perl or the Continue command in the C language. This tag can restart the rewrite operation, that is, immediately return to the loop's head.
But be careful not to create a dead loop!
' chain| C ' (linked to the next rule chained)
This tag causes the current rule to be linked to the next rule, which itself can be linked to, and can be so repeated, with its successor rule. It has the effect that if a rule is matched, it usually continues to process its successor, that is, the tag does not work, and if the rule cannot be matched, then the subsequent linked rule is ignored. For example, when performing an external redirect, you may need to delete ". www" (". www") on a directory-level rule set.
' type| T=mime-type ' (force MIME type types)
to force the MIME type of the target file to be mime-type. For example, it can be used to simulate the scriptalias instruction in Mod_alias to internally force the MIME type of all files in the mapped directory to "application/x-httpd-cgi".
' nosubreq| NS ' (for not handling internal child requests no internal sub-request)
This tag forces the override engine to skip the overriding rule when the current request is an internal child request. For example, when Mod_include tries to search for a possible directory default file (INDEX.XXX), Apache produces a child request internally. A child request, which is not necessarily useful, and may even raise an error if the entire rule set works. Therefore, you can use this tag to exclude certain rules.

According to your needs, follow these guidelines: If you use a URL prefix with a CGI script to force them to be processed by a CGI script, and the error rate (or overhead) of the child request processing is high, you can use this tag in this case.

' Nocase| NC ' (ignores case No.)
It causes pattern to ignore the case that, when pattern matches the current URL, there is no difference between ' A-Z ' and ' A-Z '.
' Qsappend| QSA ' (Append request string query string append)
This tag forces the override engine to append a request string to an existing replacement string instead of a simple replacement. You can use this tag if you need to add information to the request string by overriding the rule.
' Noescape| NE ' (no URI is escaped from the output URI escaping)
This tag prevents mod_rewrite from applying a regular URI escape rule to the overridden results. In general, special characters (such as '% ', ' $ ', '; ') And so on) will be escaped to the equivalent hexadecimal encoding. This tag can block such escapes to allow symbols such as hundred semicolons to appear in the output, such as:
rewriterule/foo/(. *)/bar?arg=p1%3d$1 [R,ne]

Can make '/foo/zed ' turn to a secure request '/bar?arg=p1=zed '.
' Passthrough| PT ' (handed over to the next processor pass through)
This tag forces the override engine to set the URI field in the internal structure Request_rec to the value of the FileName field, which is just a small modification that enables the Alias,scriptalias from other URIs to the filename translator Redirect The output of the instruction is subsequently processed. Give an example of what it means: if you want to rewrite/ABC as/def through the mod_rewrite rewrite engine, and then convert/def to/ghi through Mod_alias, you can do this:
Rewriterule ^/abc (. *)/def$1 [PT]
Alias/def/ghi

If the PT tag is omitted, although Mod_rewrite works, that is, as a URI to the filename translator using the API, it can override uri=/abc/... For filename=/def/..., however, subsequent mod_alias will fail when attempting to translate the URI to the filename.
Note: You must use this tag if you need to mix different modules that contain URIs to file name translators ... Mixed use of Mod_alias and mod_rewrite is a typical example.

For Apache hackers
If the current Apache API is in addition to the URI to the filename hook, there is a hook with a filename to the filename, you do not need this tag! However, if there is no such hook, this tag is the only solution. The Apache group discussed this issue and added a hook to the Apache 2.0 version.
' Skip| S=num ' (Skip the successor rule skip)
This tag forces the override engine to skip the NUM rule subsequent to the current matching rule. It enables the construction of a pseudo if-then-else: The last rule is a then clause, and the skipped Skip=n rule is an else clause. (IT and ' chain| C ' Mark is different!
' Env| E=var:val ' (Set environment variable environment variable)
This tag causes the value of the environment variable VAR to be Val, and Val can contain the regular expression $n and%n, which are extensible, reverse-referenced. This tag can be used more than once to set multiple variables. These variables can be referenced indirectly in many subsequent cases, but are usually in Xssi (via <!– #echo var= "var" –>) or CGI (such as $ENV {' var '}). It can also be referenced in the pattern of subsequent rewritecond instructions through%{env:var}. Use it to detach from the URL and remember some information.
' cookie|co=name:val:domain[:lifetime[:p Ath]] ' (set cookies)
It sets a cookie on the client browser. The name of the cookie is name and its value is Val. The Domain field is the field for the cookie, such as '. Apache.org ', where the optional lifetime is the number of minutes of the cookie's lifetime, and the path to the cookie is the alternative path.

Actually, there are http://man.chinaunix.net/newsoft/ApacheManual/mod/mod_rewrite.html in the Apache Handbook.

The official rewrite guide of Apache

For example, the following is the rewrite of WordPress. htaccess:

# BEGIN WordPress

Rewriteengine on
Rewritebase/

All #把learndiary. com URLs are redirected to www.learndiary.com
Rewritecond%{http_host} ^learndiary.com [NC]
Rewriterule ^ (. *) $ http://www.learndiary.com/$1 [l,r=301]

#除开 *.do form URL (required)
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewritecond%{request_uri}!. +.do
Rewriterule. /index.php [L]

If on the Nginx server, refer to the settings of the Zend Framework under Nginx

In the Linux environment to add a section of the virtual server settings, set nginx.conf as follows

server {
Listen 80;
server_name audit.local;
Root/app/audit/public;
Access_log/app/audit/logs/audit.access.log main;
Error_log/app/audit/logs/audit.error.log;
Location/{
Index index.php;
# If File not found, redirect to Zend handling, we can remove the (If) this and go directly rewrite
if (!-f $request _filename) {
Rewrite ^/(. +) $/index.php?$1& last;
}
}
Location ~* ^.+. (JS|ICO|GIF|JPG|JPEG|PDF|PNG|CSS) $ {
Access_log off;
Expires 7d;
}
Location ~. *.php?$ {
Fastcgi_pass 127.0.0.1:36;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
}
Error_page 404 Http://audit.local/error;
}

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.