<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 9, comments - 8, trackbacks - 0, articles - 3
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    Apache mod_rewrite

    Posted on 2007-01-30 23:06 Dr.Water 閱讀(1383) 評論(0)  編輯  收藏 所屬分類: 環(huán)境配置

    主要就是正則表達式的運用,除了mod_rewrite之外還有一個urlrewritefilter
    下面是一個測試二級域名映射規(guī)則

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^[^www.]+.test.ecom$
    Rewriterule ^(.+) %{HTTP_HOST}$1 [C]?
    Rewriterule ^([^www.]+)\.test\.ecom(.*) /shop_$1$2
    Rewriterule ^www.test.ecom(.*) /$1 [nc,PT]
    RewriteRule /shop_(.+)/pic/(.*)$ /pic/$2 [nc,PT]
    RewriteRule /shop_(.+)/js/(.*)$ /js/$2 [nc,PT]
    RewriteRule /shop_(.+)/css/(.*)$ /css/$2 [nc,PT]
    RewriteRule /shop_(.+)/(.+).do?(\.*)$? /$2.do?domainName=$1&%{QUERY_STRING} [L,nc]


    RewriteLog "logs/rewrite.log"
    RewriteLogLevel 3


    關(guān)鍵字段:
    ??????????????? RewriteCond 表示如果條件滿足則使用下面的Rewriterule
    ??????????????? Rewriterule 就是采用具體的正則表達式來匹配?
    ??????????????????????????????????? Rewriterule 后面還可以帶有參數(shù)

    ???????????? 見apache參考
    ?????????? http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
    ?????????

    • 'chain|C' (chained with next rule)
      This flag chains the current rule with the next rule (which itself can be chained with the following rule, and so on). This has the following effect: if a rule matches, then processing continues as usual - the flag has no effect. If the rule does not match, then all following chained rules are skipped. For instance, it can be used to remove the ``.www'' part, inside a per-directory rule set, when you let an external redirect happen (where the ``.www'' part should not occur!).
    • 'cookie|CO=NAME:VAL:domain[:lifetime[:path]]' (set cookie)
      This sets a cookie in the client's browser. The cookie's name is specified by NAME and the value is VAL. The domain field is the domain of the cookie, such as '.apache.org', the optional lifetime is the lifetime of the cookie in minutes, and the optional path is the path of the cookie
    • 'env|E=VAR:VAL' (set environment variable)
      This forces an environment variable named VAR to be set to the value VAL, where VAL can contain regexp backreferences ($N and %N) which will be expanded. You can use this flag more than once, to set more than one variable. The variables can later be dereferenced in many situations, most commonly from within XSSI (via <!--#echo var="VAR"-->) or CGI ($ENV{'VAR'}). You can also dereference the variable in a later RewriteCond pattern, using %{ENV:VAR}. Use this to strip information from URLs, while maintaining a record of that information.
    • 'forbidden|F' (force URL to be forbidden)
      This forces the current URL to be forbidden - it immediately sends back a HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with appropriate RewriteConds to conditionally block some URLs.
    • 'gone|G' (force URL to be gone)
      This forces the current URL to be gone - it immediately sends back a HTTP response of 410 (GONE). Use this flag to mark pages which no longer exist as gone.
    • 'handler|H=Content-handler' (force Content handler)
      Force the Content-handler of the target file to be Content-handler. For instance, this can be used to simulate the mod_alias directive ScriptAlias, which internally forces all files inside the mapped directory to have a handler of ``cgi-script''.
    • 'last|L' (last rule)
      Stop the rewriting process here and don't apply any more rewrite rules. This corresponds to the Perl last command or the break command in C. Use this flag to prevent the currently rewritten URL from being rewritten further by following rules. For example, use it to rewrite the root-path URL ('/') to a real one, e.g., '/e/www/'.
    • 'next|N' (next round)
      Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop.
      Be careful not to create an infinite loop!
    • 'nocase|NC' (no case)
      This makes the Pattern case-insensitive, ignoring difference between 'A-Z' and 'a-z' when Pattern is matched against the current URL.
    • 'noescape|NE' (no URI escaping of output)
      This flag prevents mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from happening. This allows percent symbols to appear in the output, as in

      RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]

      which would turn '/foo/zed' into a safe request for '/bar?arg=P1=zed'.
    • 'nosubreq|NS' (not for internal sub-requests)
      This flag forces the rewriting engine to skip a rewriting rule if the current request is an internal sub-request. For instance, sub-requests occur internally in Apache when mod_include tries to find out information about possible directory default files (index.xxx files). On sub-requests it is not always useful, and can even cause errors, if the complete set of rules are applied. Use this flag to exclude some rules.
      To decide whether or not to use this rule: if you prefix URLs with CGI-scripts, to force them to be processed by the CGI-script, it's likely that you will run into problems (or significant overhead) on sub-requests. In these cases, use this flag.
    • 'proxy|P' (force proxy)
      This flag forces the substitution part to be internally sent as a proxy request and immediately (rewrite processing stops here) put through the proxy module. You must make sure that the substitution string is a valid URI (typically starting with http://hostname) which can be handled by the Apache proxy module. If not, you will get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map remote content into the namespace of the local server.

      Note: mod_proxy must be enabled in order to use this flag.

    • 'passthrough|PT' (pass through to next handler)
      This flag forces the rewrite engine to set the uri field of the internal request_rec structure to the value of the filename field. This flag is just a hack to enable post-processing of the output of RewriteRule directives, using Alias, ScriptAlias, Redirect, and other directives from various URI-to-filename translators. For example, to rewrite /abc to /def using mod_rewrite, and then /def to /ghi using mod_alias:

      RewriteRule ^/abc(.*) /def$1 [PT]
      Alias /def /ghi

      If you omit the PT flag, mod_rewrite will rewrite uri=/abc/... to filename=/def/... as a full API-compliant URI-to-filename translator should do. Then mod_alias will try to do a URI-to-filename transition, which will fail.

      Note: You must use this flag if you want to mix directives from different modules which allow URL-to-filename translators. The typical example is the use of mod_alias and mod_rewrite.

    • 'qsappend|QSA' (query string append)
      This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.
    • 'redirect|R [=code]' (force redirect)
      Prefix Substitution with http://thishost[:thisport]/ (which makes the new URL a URI) to force a external redirection. If no code is given, a HTTP response of 302 (MOVED TEMPORARILY) will be returned. If you want to use other response codes in the range 300-400, simply specify the appropriate number or use one of the following symbolic names: temp (default), permanent, seeother. Use this for rules to canonicalize the URL and return it to the client - to translate ``/~'' into ``/u/'', or to always append a slash to /u/user, etc.
      Note: When you use this flag, make sure that the substitution field is a valid URL! Otherwise, you will be redirecting to an invalid location. Remember that this flag on its own will only prepend http://thishost[:thisport]/ to the URL, and rewriting will continue. Usually, you will want to stop rewriting at this point, and redirect immediately. To stop rewriting, you should add the 'L' flag.
    • 'skip|S=num' (skip next rule(s))
      This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N, where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!)
    • 'type|T=MIME-type' (force MIME type)
      Force the MIME-type of the target file to be MIME-type. This can be used to set up the content-type based on some conditions. For example, the following snippet allows .php files to be displayed by mod_php if they are called with the .phps extension:

      RewriteRule ^(.+\.php)s$ $1 [T=application/x-httpd-php-source]


    ????????????????


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     
    主站蜘蛛池模板: 亚洲高清一区二区三区| 国产亚洲视频在线观看网址| 永久免费AV无码国产网站| 亚洲最大天堂无码精品区| 国产乱子伦精品免费无码专区| 高潮毛片无遮挡高清免费视频| 亚洲精品无码av人在线观看| 97性无码区免费| 免费大片av手机看片高清| 久久青草亚洲AV无码麻豆| 免费看国产精品3a黄的视频| 亚洲免费日韩无码系列| 亚洲天堂一区在线| 亚洲人成网站在线观看青青 | 免费国产精品视频| 久草免费福利视频| 亚洲精品美女久久7777777 | 新最免费影视大全在线播放| 亚洲国产精品婷婷久久| 四虎免费永久在线播放| 最近2019免费中文字幕视频三| 国产亚洲情侣久久精品| 亚洲综合图片小说区热久久| 亚洲精品久久久www| 一本无码人妻在中文字幕免费| 成人片黄网站色大片免费观看cn| 亚洲人成网国产最新在线| 国产精品亚洲精品日韩已满| 国产精品视频免费一区二区三区| 在线观看的免费网站无遮挡| 精选影视免费在线 | 青青草无码免费一二三区| 国产亚洲情侣久久精品| 亚洲天堂一区二区三区四区| 亚洲AV无码一区东京热| 免费一级大黄特色大片| 免费无码又爽又刺激聊天APP| 日韩免费在线视频| 久久av免费天堂小草播放| 男女超爽视频免费播放| 亚洲最大的成人网|