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

Mod rewrite 重写URL-如何获取主机名和路径?,mod-rewrite,Mod Rewrite,我想使用mod_rewrite来隐藏生成XML文件的URL 因此,如果这是请求的URL: 页面cid=8001&srt=po 应执行此URL: http://www.xmldomain.com/bla/页面cid=8001&srt=po&rtype=xslt&xsl=页面.xsl http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=http://%{http_HOST}$1$2.xsl* %{HTTP_HOST}是www.domain.com $1

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

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

页面cid=8001&srt=po

应执行此URL:

http://www.xmldomain.com/bla/页面cid=8001&srt=po&rtype=xslt&xsl=页面.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
应该是
页面

$3
应该是
cid=8001&srt=po


谢谢

您无法准确地说出要匹配的URL,因此我假设您只想匹配,但编写时要将规则扩展到同一域的更通用的URL,这并不重要。如果你需要更多的域名,也可以这样做。我也不知道你说的“隐藏”是什么意思。如果要重定向而不是代理,请将括号内的P标志替换为R标志

#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避免对百分号进行双重编码。

这里有一个更动态的参数,应该完全符合您的要求

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

我不知道您最后想要什么样的选项,但我假设您想要使用重定向。

这正是我想要的,但在我的服务器上不起作用。找不到该页。mod_rewrite处于活动状态,我已经尝试了一些简单的示例,它正在工作。你能帮我找出问题所在吗?我为此打开了一个新线程。请看这里: