发布于 2016-02-05 07:46:56 | 217 次阅读 | 评论: 0 | 来源: 网友投递
Apache Web服务器
Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件。
如下规则:
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]
要达到这个目的,有两个方法。
第一种方式,配合 mod_proxy ,将第一条重写规则改为
# sitemap index xml rewrite
RewriteRule ^sitemap_([a-zA-Z0-9_\-]+)\.xml$ /sitemap/$1 [P,L]
第二种方法,将第一条规则改为
# 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]
有趣的是在 Rewrite 的过程中 REQUEST_URI 的值始终保持是原始的请求URI,但在 mod_setenvif 中提供的 SetEnvIf / SetEnvIfNoCase 中所使用的 Request_URI 属性得到的却是经过 rewrite 之后的地址而非原始 GET/POST 中的 URI。
所以如果在 httpd.conf / httpd-vhosts.conf 中想使用
SetEnvIfNoCase Request_URI "sitemap" ...
SetEnvIfNoCase Request_URI "(^/sitemap_.*\.xml)" MY_REQUEST_URI_BF_REWRITE=$1
SetEnvIfNoCase MY_REQUEST_URI_BF_REWRITE "sitemap" ...