1

This is a follow-up of this question: Rewrite URL - how to get the hostname and the path?
And a copy of this: mod_rewrite RewriteRule is not working

I got this Rewrite Rule:

RewriteEngine On
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

it seems to be correct, and exactly what I need. But it doesn't work on my server. I get a 404 page not found error.

mod_rewrite is enabled, as the following simple rule is working fine:

 RewriteEngine On
 RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]

Can you help?

Thanks

3
  • 1
    Is the double http:// at the end (http://http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=$1/$2.xsl) intentional?
    – aardbol
    May 21, 2010 at 10:43
  • no. it wasn't intentional. i removed one.
    – big_p
    May 21, 2010 at 10:55
  • stackoverflow.com/questions/2875405/… seems like a correct response to me. What's wrong with it? May 21, 2010 at 11:27

1 Answer 1

2

According to the documentation, by default

The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string. If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.

So you cannot extract the hostname nor the query string this way. The simples way is to use the %{HTTP_HOST} and %{QUERY_STRING} server variables in the rewrite rule:

RewriteRule ^/(.*)$ http://www.xmldomain.com/bla/$1?%{QUERY_STRING}&rtype=xslt&xsl=%{HTTP_HOST}/$1.xsl

EDIT

If you want to test the full URL, then you can use RewriteCond like this (note the % sign instead of the $ sign in the rewrite rule):

RewriteCond %{HTTP_HOST}/%{REQUEST_URI}&%{QUERY_STRING} ...pattern...
RewriteRule . http://www.xmldomain.com/bla/%2?%3&rtype=xslt&xsl=%1/%2.xsl

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .