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

People I have been working for days in this and I,m no able to make it work.

I,m trying to do a RewriteRule in my apache server but is not working.

if i use a simple url like this it works perfect.

RewriteEngine On
RewriteRule ^(/.php/m/) htp://www.index.php

but if i use a complex url dont work , something like this:

RewriteEngine On
RewriteRule ^(/index.php?option=com_rsform&Itemid=8&lang=en) htp://www.index.php

does some body know why apache is not understanding this url what i,m missing

index.php?option=com_rsform&Itemid=8&lang=en

share|improve this question

migrated from stackoverflow.com Jan 2 '10 at 8:57

This question came from our site for professional and enthusiast programmers.

    
What do you mean by www.index.php? that sounds weird –  naivists Jan 1 '10 at 17:37
    
sorry htp://www.index.php is only for the example, the real url will be something like htp://www.mydomain.com/index.php, but my real problem is the first url index.php?option=com_rsform&Itemid=8&lang=en Apache won,t rewrite when i hit that url it seems that it don,t recognize the url or don,t understand it " –  Cano63 Jan 1 '10 at 17:42
    
Have you tried escaping the ? (replace it with \?). It has a special meaning when used in a regular expression, as you're doing. –  Wim Jan 1 '10 at 17:46
    
yes i try it like this: index.php\?option=com_rsform&ItemId=8&lang=en but din,t work –  Cano63 Jan 1 '10 at 17:54
    
Actually I don't think the query part is included in the match with a RewriteRule. You can use a RewriteCond expression using %{QUERY_STRING} though. –  Wim Jan 1 '10 at 17:58

1 Answer 1

The query part is not included when you match an URL with a RewriteRule, see this part of the docs:

What is matched?

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.

As suggested by the docs, you can use a RewriteCond expression to match on %{QUERY_STRING}:

RewriteCond %{QUERY_STRING} ^option=com_rsform&Itemid=8&lang=en$
RewriteRule ^index.php$ http://www.index.php

Note that this only works when the query string is exactly the one you're matching. An equivalent query string in which the order of the arguments is changed, f.i. option=com_rsform&lang=en&Itemid=8, will not be matched. So in this case, I think you'd be better to send all requests to your PHP script, and have that look at $_GET and decide whether to forward or not.

share|improve this answer

Your Answer

 
discard

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