重写URL - 如何获取主机名和路径?

时间:2010-05-20 15:43:46

标签: mod-rewrite

我想使用mod_rewrite来隐藏生成我的XML文件的URL。

因此,如果这是请求的URL:

  

http://www.domain.com/path/to/ 页面?的 CID = 8001&安培; SRT = PO

应执行此网址:

  

http:// www.xmldomain.com/bla/ 页面 cid = 8001& srt = po & rtype = xslt& xsl = http://www.domain.com/path/to/ .xsl

     

http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=http://%{HTTP_HOST}$1$2.xsl*

%{HTTP_HOST}www.domain.com
$1应为/path/to/ (我该怎么做?)
$2应为page $3应为cid=8001&srt=po

谢谢!

2 个答案:

答案 0 :(得分:1)

您没有确切地告诉您要匹配哪些网址,因此我假设您只想匹配http://www.domain.com/path/to/page,但是将其编写为将规则扩展到同一域的更一般网址的方式是不重要的。如果您需要更多域名,也可以这样做。我也不知道“隐藏”是什么意思。如果要重定向而不是代理,请用括号替换括号内的P标志。

#should be put in the virtual host for www.domain.com
RewriteRule ^(/path/to/page)$ http://www.xmldomain.com/bla/page?rtype=xslt&xsl=http%3A%2F%2Fwww.domain.com$1.xsl%2A [QSA,B,P,NE]

QSA附加cid和str参数,B转义路径,P代理请求,NE避免百分号的双重编码。

答案 1 :(得分:0)

这里有一点动态,应该完全按照你要求的方式进行。

RewriteRule ^(http://[-A-Za-z0-9+&@#/%=~_|!:,.;]*)/([-A-Za-z0-9+&@#/%=~_|!:,.;]*)\?([A-Za-z0-9+&@#/%=~_|!:,.;]*)$ http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=$1/$2.xsl

我不知道你最后想要什么样的选项,但我认为你想要使用重定向。

相关问题