tags:

views:

56

answers:

2

Hi,

This is a follow-up of this question: Rewrite URL - how to get the hostname and the path?

I got this Rewrite Rule:

RewriteEngine On
RewriteRule ^(http://[-A-Za-z0-9+&@#/%=~_|!:,.;]*)/([-A-Za-z0-9+&@#/%=~_|!:,.;]*)\?([A-Za-z0-9+&@#/%=~_|!:,.;]*)$ http://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

A: 

It believe it's not correct. You cannot use a url as the first operand of RewriteRule.

What you should write instead of

RewriteRule ^(http://[-A-Za-z0-9+&@#/%=~_|!:,.;]*)/([-A-Za-z0-9+&@#/%=~_|!:,.;]*)\?([A-Za-z0-9+&@#/%=~_|!:,.;]*)$ http://http://www.xmldomain.com/bla/$2?$3&rtype=xslt&xsl=$1/$2.xsl

is (edit: for some reason you want to match the last portion path, I'll oblige)

RewriteCond %{HTTP_HOST} !=""
RewriteRule ^/(.*?)([^/]+)(?:/)?$ http://www.xmldomain.com/bla/page?rtype=xslt&xsl=http%3A%2F%2F%{HTTP_HOST}%2F$1$2.xsl%2A [QSA,B,P,NE]

Also note that rewrite rules are not automatically inherited by virtual hosts. You must activate inheritance explicitly.

Artefacto
buggy1985
That's my fault, I provided the regex. Does the regex operate on the variables though?
Arda Xi
@buggy1985 ok, then what's the $1?
Artefacto
@Artefacto the path. look here: http://stackoverflow.com/questions/2875405/rewrite-url-how-to-get-the-hostname-and-the-path
buggy1985
@buggy1985 I don't get it. Having $1 match /path/to/, $2 match page and rewrite to $1$2 is the same as having $1 match /path/to/page and rewrite to $1. But I'll edit the answer anyway
Artefacto
@Artefacto that's true, but I'm using $2 twice. without the path, after /www.xmldomain.com/bla/, and with path, after %{HTTP_HOST}
buggy1985
A: 

maybe try this

RewriteRule ^/(.+)/page/([^/]+)/(.*)$ domain/index.php?page=$2&host=%{HTTP_HOST} [QSA,NC,L]
Don