用了好几次rewrite,用的次数不是非常多,每次都忘,都得又一次上网上找一堆现看,总结一下,以免以后忘了

=====================分隔符=====================

注意下面几点:

1、载入rewrite模块,LoadModule rewrite_module modules/mod_rewrite.so

2、假设是用vhost里配置,则在vhost里打开RewriteEngine on(htaccess文件配置的方式没实用过)

用过的配置:

场景一:当域名是aaa.bbb的时候。跳转到aaa.ccc.bbb这个域名

RewriteEngine on

RewriteCond %{HTTP_HOST} ^aaa\.bbb$ [NC]

RewriteRule ^/(.*)$  http://aaa.ccc.bbb/$1  [R=301,L,NC]

%{HTTP_HOST}匹配域名,^表示匹配開始,$表示匹配结束,各自是匹配字符串的左右界,能够不同一时候出现。\.表示转义,仅仅匹配.。否则就变成随意单个字符了

NC(no case) 不区分大写和小写,

.是随意单个字符,.*就是随意数量的随意字符,()是子字符串。所以^/(.*)$表示域名后随意路径,这里推測。应该能够省略$,这里的.,没实用\转义,是由于这部分不是正则,$1匹配的是第一个()里的内容。R=301表示永久跳转。

场景二:把/testt/这个请求。转到/image/下,可是/testt/xxxx。不发生跳转

RewriteEngine on

RewriteRule ^/testt/$  http://localhost:8000/image/  [R=301,L,NC]

对于query string的操作,下面引自官方文档

Modifying the Query String

By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected
into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.

=====================分隔符=====================

參考资料:

正則表達式中各种字符的含义 http://www.cnblogs.com/afarmer/archive/2011/08/29/2158860.html

apache的rewrite规则使用说明 http://www.jb51.net/article/48780.htm

13个有用的Apache Rewrite重写规则 http://www.jb51.net/article/47907.htm

最新文章

  1. 与锤子手机HR的对话——创业没有联合创始人,CTO 等高管会把它当做自己的事业吗?
  2. PAT A 1014. Waiting in Line (30)【队列模拟】
  3. jenkins 设置权限后管理员登陆提示:Access Denied admin没有Overall/Read权限
  4. 理解中WebAPI的属性和相关操作 FormBody和 FormUri等(WebAPI 二)
  5. crontab中使用mysql问题
  6. commons-logging和slf4j都是日志的接口
  7. Unit Of Work-工作单元
  8. nginx(2)
  9. 降低Redis内存占用
  10. Codeforces Round #410 (Div. 2)C. Mike and gcd problem
  11. 2015级C++第4周项目 函数
  12. 帝国cms中下拉框select的绑定
  13. adoquery.refresh和adoquery.query的区别
  14. springboot系列九,springboot整合邮件服务、整合定时任务调度
  15. 第四章:初识CSS3
  16. [vue]声明式导航和编程式导航
  17. angularjs探秘<三> 控制器controller及angular项目结构
  18. HTTP请求的GET与POST方式的区别
  19. 使用Git将本地项目上传到Github操作详解
  20. oc 调用c语言方法和oc的方法调用

热门文章

  1. NEFU 117
  2. [React Router] Prevent Navigation with the React Router Prompt Component
  3. 嵌入式linux和pc机的linux对照
  4. Regexp-Utils:基本
  5. div position:fixed后,水平居中的问题
  6. Dragon Balls[HDU3635]
  7. vue中使用UEditor编辑器 -- 2
  8. getElementsByClassName 方法兼容性封装方法二
  9. Python学习——BeautifulSoup篇
  10. ZBrush中移动笔刷介绍