设为首页 收藏本站
查看: 521|回复: 0

[经验分享] Apache mod_rewrite 小结

[复制链接]

尚未签到

发表于 2017-1-2 07:32:25 | 显示全部楼层 |阅读模式
  mod_rewrite
  Apache HTTP Server
  Enable htaccess on Apache
  1. uncomment this line in httpd.conf:
  LoadModule rewrite_module modules/mod_rewrite.so
  
  2. change directory setting in httpd.conf:
  <Directory />
  Options FollowSymLinks
  AllowOverride All
  Order deny,allow
  Deny from all
  Satisfy all
  </Directory>
  
  Configures what features are available in a particular directory
  
  Options 属性:
  Indexes     当该目录下没有index.*时则以ftp-style列出该目录下所有文件
  Includes    Allow server-wide includes
  FollowSymLinks 当该目录下软连接的文件/目录链接到外部目录时,仍然可以正常显示。
  MultiViews   由一个*.var管理同一网页的多种语言版本,如apache默认主页多种语言的index.html
  ExecCGI     允许执行CGI程序
  ALL       开启除MultiViews之外的属性
  None      禁止所有属性
  
  AllowOverride 是否允许使用.htaccess覆盖某些设定(All None FileInfo AuthConfig Limit)
  Order allow,deny : 控制访问权限
  Order deny,allow
  deny from test.org 拒绝test.org访问
  deny from 192.168.0.100 拒绝192.168.0.100访问
  allow from 192.168.0.1 允许192.168.0.1 访问
  
  http://httpd.apache.org/docs/2.0/mod/core.html
  http://m.oschina.net/bbs/thread/176
  authentication
  
  http://www.htaccesstools.com/htaccess-authentication/
  
  .htaccess
  Reference:
  http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
  http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
  Examples:
  http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html
  http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide_advanced.html
  http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html#default-mod-rewrite-hint
  http://www.webmasterworld.com/forum92/2524.htm
  
  Tools:
  http://cooletips.de/htaccess/
  http://www.htaccesstools.com/
  
  usually it is used to transfer from static URL to dynamic URL
  
  #Error pages
  ErrorDocument 404 http://www.backbase.com/errors/404.php
  
  RewriteRule directives
  
  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. Remember, however, that if the RewriteRule generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the first RewriteRule.
  
  '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'.
  
  '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, 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.
  
    While this is typically used for redirects, any valid status code can be given here. If the status code is outside the redirect range (300-399), then the Substitution string is dropped and rewriting is stopped as if the L flag was used.
  
  RewriteCond directives
  used before RewriteRule directives
  
  # RewriteRule backreferences: These are backreferences of the form $N (0 <= N <= 9), which provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current set of RewriteCond conditions..
  # RewriteCond backreferences: These are backreferences of the form %N (1 <= N <= 9), which provide access to the grouped parts (again, in parentheses) of the pattern, from the last matched RewriteCond in the current set of conditions.
  # RewriteMap expansions: These are expansions of the form ${mapname:key|default}. See the documentation for RewriteMap for more details.
  # Server-Variables: These are variables of the form %{ NAME_OF_VARIABLE } where NAME_OF_VARIABLE can be a string taken from the following list:
  HTTP headers: connection & request:
  HTTP_USER_AGENT
  HTTP_REFERER
  HTTP_COOKIE
  HTTP_FORWARDED
  HTTP_HOST
  HTTP_PROXY_CONNECTION
  HTTP_ACCEPT
  REMOTE_ADDR
  REMOTE_HOST
  REMOTE_PORT
  REMOTE_USER
  REMOTE_IDENT
  REQUEST_METHOD
  SCRIPT_FILENAME
  PATH_INFO
  QUERY_STRING
  AUTH_TYPE
  
  server internals: system stuff: specials:
  DOCUMENT_ROOT
  SERVER_ADMIN
  SERVER_NAME
  SERVER_ADDR
  SERVER_PORT
  SERVER_PROTOCOL
  SERVER_SOFTWARE
  TIME_YEAR
  TIME_MON
  TIME_DAY
  TIME_HOUR
  TIME_MIN
  TIME_SEC
  TIME_WDAY
  TIME
  API_VERSION
  THE_REQUEST
  REQUEST_URI
  REQUEST_FILENAME
  IS_SUBREQ
  HTTPS

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-322548-1-1.html 上篇帖子: apache 日志分析常见命令 下篇帖子: apache负载均衡设置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表