Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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+&@#/%=~_|!:,.;]*)$$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?


share|improve this question
Is the double http:// at the end (http://$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… seems like a correct response to me. What's wrong with it? – Karol Piczak May 21 '10 at 11:27

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 ^/(.*)$$1?%{QUERY_STRING}&rtype=xslt&xsl=%{HTTP_HOST}/$1.xsl


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

Your Answer


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.