tags:

views:

36

answers:

3

Hello,

I want to use mod_rewrite to hide the URL, that generates my XML file.

So if this is the requested URL:

http://www.domain.com/path/to/ page ? cid=8001&srt=po

This URL should be executed:

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

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

%{HTTP_HOST} is www.domain.com
$1 should be /path/to/ (How can I do this?)
$2 should be page
$3 should be cid=8001&srt=po

Thanks!

A: 

See : http://articles.sitepoint.com/article/guide-url-rewriting/1

Michaël
I can't find the answer of my question in this tutorial. Can you be more explaining?
buggy1985
+1  A: 

You don't tell exactly which urls you want to match, so I'll assume you want to match only http://www.domain.com/path/to/page, but write it a way that extending the rule to more general urls for the same domain is trivial. If you need more domains it can be done too. I also don't know what you mean with "hide". If you want to redirect instead of proxy, substitute the P flag inside the brackets with the R flag.

#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 appends cid and str parameters, B escapes the path, P proxies the request and NE avoids double encoding of the percent signs.

Artefacto
A: 

Here's a bit more dynamic one, should do exactly what you're looking for.

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

I have no idea what kind of options you want at the end, but I'd assume you'd want to use a redirect.

Arda Xi
this is exactly what I'm looking for, but it doesn't work on my server. the page cannot be found. mod_rewrite is active, I've tried some trivial examples, and it's working. can you help me to find out what the problem is?
buggy1985
I opened a new thread for this. See here: http://stackoverflow.com/questions/2880996/mod-rewrite-rewriterule-is-not-working
buggy1985