如下规则:
复制代码 代码如下:
RewriteEngine on
# sitemap index xml rewrite
RewriteRule ^sitemap_([a-zA-Z0-9_\-]+)\.xml$ /sitemap/$1
# redirected all invalid request the the index bootstrap
RewriteRule !\.(htm|txt|xml|css|js|swf|gif|jpg|png|ico)$ index.php [L]
假设访问 sitemap_index.xml ,当经过两次RewriteRule之后,传给bootstrap程序 index.php 的 $_SERVER['REQUEST_URI'] 值仍然是 /sitemap_index.xml ,但实际上希望是 /sitemap/index ,这样 index.php 才能正确的进行 url route 。
要达到这个目的,有两个方法。
第一种方式,配合 mod_proxy ,将第一条重写规则改为
复制代码 代码如下:
# sitemap index xml rewrite
RewriteRule ^sitemap_([a-zA-Z0-9_\-]+)\.xml$ /sitemap/$1 [P,L]
这样将在内部产生一个新的URL请求, REQUEST_URI 的值也就变成了新的 /sitemap/index 。但这种方法制造了额外的一次 http 请求。
第二种方法,将第一条规则改为
复制代码 代码如下:
# sitemap index xml rewrite
RewriteRule ^sitemap_([a-zA-Z0-9_\-]+)\.xml$ /sitemap/$1 [E=REQUEST_URI:/sitemap/$1]
或者
复制代码 代码如下:
# sitemap index xml rewrite
RewriteRule ^sitemap_([a-zA-Z0-9_\-]+)\.xml$ index.php [E=REQUEST_URI:/sitemap/$1,L]
然后通过 $_SERVER['REDIRECT_REQUEST_URI'] 变量得到 值 /sitemap/index (注意使用 E 设置环境变量的时候,mod_rewrite 自动给变量加上 REDIRECT_ 前缀)。
有趣的是在 Rewrite 的过程中 REQUEST_URI 的值始终保持是原始的请求URI,但在 mod_setenvif 中提供的 SetEnvIf / SetEnvIfNoCase 中所使用的 Request_URI 属性得到的却是经过 rewrite 之后的地址而非原始 GET/POST 中的 URI。
所以如果在 httpd.conf / httpd-vhosts.conf 中想使用
复制代码 代码如下:
SetEnvIfNoCase Request_URI "sitemap" ...
来针对 sitemap 设置环境变量的话是不起作用的,因为这时候传给 SetEnvIfNoCase 进行判断的 Request_URI 是 index.php 而不是 sitemap_index.xml 或 sitemap/index 。想要得到原始的 Request_URI 信息就必须在 rewrite 规则的最开始进行保存,比如在 rewrite 规则开头加入
复制代码 代码如下:
SetEnvIfNoCase Request_URI "(^/sitemap_.*\.xml)" MY_REQUEST_URI_BF_REWRITE=$1
然后在需要的地方使用
复制代码 代码如下:
SetEnvIfNoCase MY_REQUEST_URI_BF_REWRITE "sitemap" ...
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 纯音入心系列纯音乐《古筝与现代音乐的交织》1CD[MP3][96MB]
- 王俪婷.2011-ROMANCE【华研国际】【WAV+CUE】
- 狮子合唱团.2016-LION(引进版)【华纳】【WAV+CUE】
- 范文芳.1996-FNNTASY【HYPE】【WAV+CUE】
- 纯音入心系列纯音乐《韵味古筝曲》1CD[MP3][146.2MB]
- 纯音入心系列纯音乐《古筝系列-传统乐曲》1CD[MP3][974.7MB]
- 纯音入心系列纯音乐《古筝系列-弦凝指咽声停处》1CD[MP3][656.5MB]
- 群星.1994-大烂片2辑【派森】【WAV+CUE】
- 吴倩莲.1997-望爱【EMI百代】【WAV+CUE】
- 杨千嬅.2002-万紫千红演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郭采洁.2015-Begin.Again爱造飞鸡【华纳】【FLAC分轨】
- 许志安.2011-ON.AND.ON【东亚】【WAV+CUE】
- 潘秀琼.1994-木兰从军【名将】【WAV+CUE】
- 纯音入心系列纯音乐《古筝系列-当流行乐遇到古筝》1CD[MP3][1.9GB]
- 纯音入心系列纯音乐《精选古筝名曲100首》1CD[MP3][388.7MB]