Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

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

1 Answer 1

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.