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
From stackoverflow
-
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.xslis (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.
buggy1985 : ok. but this doesn't help me solve my problem. I need to catch string after the last slash ("page") separately. The subsitution part should look like this: http: //www.xmldomain.com/bla/$2?rtype=xslt&xsl=http%3A%2F%2F%{HTTP_HOST}%2F$1$2.xsl How does the Pattern part look like to do this?Arda Xi : That's my fault, I provided the regex. Does the regex operate on the variables though?Artefacto : @buggy1985 ok, then what's the $1?buggy1985 : @Artefacto the path. look here: http://stackoverflow.com/questions/2875405/rewrite-url-how-to-get-the-hostname-and-the-pathArtefacto : @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 anywaybuggy1985 : @Artefacto that's true, but I'm using $2 twice. without the path, after /www.xmldomain.com/bla/, and with path, after %{HTTP_HOST} -
maybe try this
RewriteRule ^/(.+)/page/([^/]+)/(.*)$ domain/index.php?page=$2&host=%{HTTP_HOST} [QSA,NC,L]
0 comments:
Post a Comment